I wanted to add button in the html table column from the C#. I have attached the code behind and asp.net in the code.button is creating in the column for each row but not calling to the click event.
public string getWhileLoopData()
{
string htmlStr = "";
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT Id,EmployeeEmail,PayReference from EmployeeDetails";
thisConnection.Open();
SqlDataReader reader = thisCommand.ExecuteReader();
PlaceHolder PlaceHolder1 = new PlaceHolder();
while (reader.Read())
{
long id = reader.GetInt64(0);
string Name = reader.GetString(1);
string Pass = reader.GetString(2);[enter image description here][1]
htmlStr += "<tr class='row_data'><th data-employee-id='" + id + "'>" + id + "</th><th>" + Name + "</th><th>" + Pass + "</th><th> <input id='Button1' runat='server' class='button right' onserverclick='Button1_Click' type='submit' value='Update' /> </th></tr>";
}
thisConnection.Close();
return htmlStr;
}
ASP.NET code is below
<table id="myTable" class="table table-striped">
<thead align="left" style="background-color: #004080; color: White;">
<tr>
<th>
Id
</th>
<th>
Email Address
</th>
<th>
Empr Paye Ref.
</th>
<th>
Open
</th>
</tr>
</thead>
<tbody>
<%=getWhileLoopData()%>
</tbody>
</table>
There's no event called onserverclick
. You can use asp button instead of html button and use onclick
event.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.