【发布时间】:2016-06-09 15:34:13
【问题描述】:
我想在 C# 的 html 表格列中添加按钮。我已经附加了后面的代码,并且在 code.button 中的 asp.net 正在为每一行的列中创建,但没有调用 click 事件。
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 代码如下
<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>
【问题讨论】:
-
使用 c# 中的原始数据,您将能够引发 javascript 事件而不是服务器回发。您将需要像中继器一样支持模板的控件,您可以在其中指定单击事件。顺便说一句,您也可以使用 javascript 手动回发
-
只是好奇为什么不为此使用 ASP.net 网格或列表视图控件?
-
我想使用 HTML 表格和 JQuery 进行分页和搜索,我的代码适合网格响应。