如何找到复选框的CheckedChanged事件的ListView在ASP.NET中的数据钥匙吗? [英] How to find the data key on CheckedChanged event of checkbox in ListView in ASP.NET?
问题描述
我正在使用项模板我使用一个标签和一个复选框内的一个列表视图。
我想,只要用户点击复选框应在table.i更新值时在listview.on datakey价值的基础上,应在表进行更新使用datakeys。查询是:
I am using a list view inside that in item template i am using a label and a checkbox. I want that whenever user clicks on the check box the value should be updated in a table.i am using a datakeys in listview.on the basis of datakey value should be updated in the table. Query is:
string updateQuery = "UPDATE [TABLE] SET [COLUMN] = " + Convert.ToInt32(chk.Checked) + " WHERE PK_ID =" + dataKey + " ";`
我也想在显示结果的一些帮助,因为它是table.means内如果特定PKID表列中的值是1,那么该复选框建议立即进行删除进行检查。
also i want some help in displaying the result as it is inside the table.means if the value for column in table for a particular pkid is 1 then the checkbox shoul be checked.
下面是code片断:
<asp:ListView ID="lvFocusArea" runat="server" DataKeyNames="PK_ID" OnItemDataBound="lvFocusArea_ItemDataBound">
<LayoutTemplate>
<table border="0" cellpadding="1" width="400px">
<tr style="background-color: #E5E5FE">
<th align="left">
Focus Area
</th>
<th>
Is Current Focused
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td width="80%">
<asp:Label ID="lblFocusArea" runat="server" Text=""><%#Eval("FOCUS_AREA_NAME") %></asp:Label>
</td>
<td align="center" width="20%">
<asp:CheckBox ID="chkFocusArea" runat="server" OnCheckedChanged="chkFocusArea_CheckedChanged" AutoPostBack="true" />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #EFEFEF">
<td>
<asp:Label ID="lblFocusArea" runat="server" Text=""><%#Eval("FOCUS_AREA_NAME") %></asp:Label>
</td>
<td align="center">
<asp:CheckBox ID="chkFocusArea" runat="server" OnCheckedChanged="chkFocusArea_CheckedChanged" AutoPostBack="true" />
</td>
</tr>
</AlternatingItemTemplate>
<SelectedItemTemplate>
<td>
item selected
</td>
</SelectedItemTemplate>
</asp:ListView>
帮我。
推荐答案
检查了这一点:可能有助于解决歌厅datakey的您的问题
Check this out : may help to resolve your issue of geting datakey
protected void chkFocusArea_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
ListViewItem item = (ListViewItem)cb.NamingContainer;
ListViewDataItem dataItem = (ListViewDataItem)item ;
string code = ListView1.DataKeys[dataItem.DisplayIndex].Value.ToString();
}
这篇关于如何找到复选框的CheckedChanged事件的ListView在ASP.NET中的数据钥匙吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!