Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an HTML table with a repeater. In this table, I added a button column. It is an HTML button because ASP buttons not working inside of the tag. Therefore, I added an ASP hidden field inside of this HTML button to get selected row ID. I tried several ways to get the ID from the hidden field. I want to get selected row ID when the button click.

What I have tried:

I have tried followings

I have tried this code but shows error in SendValueToSender(id); line. SendValueToSender is shown in red line using suggestions It generated method. But when I run the code and click the button shows error.

button_edit_ServerClick

protected void button_edit_ServerClick(object sender, EventArgs e)
    {
        try
        {
            var btn = (HtmlButton)sender;
            var child = btn.FindControl("hidden");
            string id = Convert.ToString(((HiddenField)child).Value);
            SendValueToSender(id);
            Response.Write("id" + id);

        }
        catch (Exception exception)
        {
            Response.Write(exception);
        }
    }


Generated method for SendValueToSender

private void SendValueToSender(string id)
    {
        throw new NotImplementedException();
    }


Error-After add SendValueToSender method

System.NotImplementedException: The method or operation is not implemented. at EasyTravel.Manage.ManageNode.SendValueToSender(String id) in C:\Users\kularathna\source\repos\EasyTravel\EasyTravel\Manage\ManageNode.aspx.cs:line 241 at EasyTravel.Manage.ManageNode.button_edit_ServerClick(Object sender, EventArgs e) in C:\Users\kularathna\source\repos\EasyTravel\EasyTravel\Manage\ManageNode.aspx.cs:line 229

229 - SendValueToSender(id);
241 - throw new NotImplementedException();


PageLoad Method

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //Create Database Connection
            SqlConnection con = new SqlConnection("Data Source= LAPTOP-J70EHC58 ; Initial Catalog= Bus_Management_System ; Integrated Security = True ; Connect Timeout = 30 ; ");
        con.Open();

        //Retrieve node details
        string sqlst = "SELECT * FROM Node ";
        SqlDataAdapter sqlData = new SqlDataAdapter(sqlst, con);
        DataTable dt = new DataTable();
        sqlData.Fill(dt);
        rptrNode.DataSource = dt;
        rptrNode.DataBind();

        }

    }


ManageNode.aspx

<table id="datatable-buttons" class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>Node_ID</th>
                                        <th>Node_Name</th>
                                        <th>Starting_Node</th>
                                        <th>Ending_Node</th>
                                        <th>Distance_Between_Nodes</th>
                                        <th>Ticket_Price</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>

                                <tbody>
                                    <asp:Repeater ID="rptrNode" runat="server">
                                        <ItemTemplate>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lblNodeID" runat="server" Text='<%# Eval("Node_ID") %>'></asp:Label></td>
                                                <td>
                                                    <asp:Label ID="lblNodeName" runat="server" Text='<%# Eval("Node_Name") %>'></asp:Label></td>
                                                <td>
                                                    <asp:Label ID="lblStartingNode" runat="server" Text='<%# Eval("Starting_Node") %>'></asp:Label></td>
                                                <td>
                                                    <asp:Label ID="lblEndingNode" runat="server" Text='<%# Eval("Ending_Node") %>'></asp:Label></td>
                                                <td>
                                                    <asp:Label ID="lblDistance" runat="server" Text='<%# Eval("Distance_Between_Nodes") %>'></asp:Label></td>
                                                <td>
                                                    <asp:Label ID="lblTicketPrice" runat="server" Text='<%# Eval("Ticket_Price") %>'></asp:Label></td>
                                                <td>
                                                    <button runat="server" clientidmode="Static" class="btn btn-success" id="button_edit" onserverclick="button_edit_ServerClick">
                                                        <asp:HiddenField runat="server" ID="hidden" Value='<%#Eval("Node_ID") %>' />
                                                        Edit
                                                    </button>

                                                </td>
                                            </tr>

                                        </ItemTemplate>
                                    </asp:Repeater>
                                </tbody>


                            </table>


Button Column(It is in above ManageNode.aspx)

<td>
         <button runat="server" clientidmode="Static" class="btn btn-success" id="button_edit" onserverclick="button_edit_ServerClick">
             <asp:HiddenField runat="server" ID="hidden" Value='<%#Eval("Node_ID") %>' />Edit
         </button>
     </td>
Posted
Updated 17-May-19 22:47pm

1 solution

The error you get is a NotImplementedException, which is normal since the line
C#
throw new NotImplementedException();
is reached.

Which means that the click of the button acually calls the SendValueTosender() method. You may have forgotten to implement the SendValueToSender() method.
 
Share this answer
 
Comments
chapa Kularathne 18-May-19 5:05am    
can you help me to create SendValueToSender method? Because I don't know what should I do inside that method
phil.o 18-May-19 5:13am    
I can't since I do not know what this method is supposed to do, nor on which database table(s) it should act, nor the logic to implement. Besides, implementing this method is your job, not ours. We would gladly help you with some code you wrote which presents issues, but I do not think anyone here is up to do it all for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900