【发布时间】:2017-09-04 17:38:08
【问题描述】:
我有一个网格视图,其中一个数据字段是一个复选框。我阅读了数据库并填充了gridview。我还有一个 OnRowCommand 项目。当我选择一行时,我想获取复选框的值并将其放在表单上的标签中。
HTML :
<asp:GridView ID="grv_Contacts" runat="server"
DataKeyNames="Cntc_Id" AutoGenerateColumns="False"
CssClass="myGrid" OnRowCommand="grv_Contacts_RowCommand">
<Columns>
<asp:CommandField SelectText="SEL"
ShowSelectButton="True" ControlStyle-CssClass="btn btn-warning myBtn-xs">
<ControlStyle Font-Bold="True" ForeColor="Blue" Width="40px" />
</asp:CommandField>
<asp:BoundField DataField="Cntc_Id" HeaderStyle-CssClass="myHidden" ItemStyle-CssClass="myHidden">
</asp:BoundField>
<asp:BoundField DataField="Cntc_Name" HeaderText="Name" SortExpression="Cntc_Name">
<HeaderStyle Width="180px" />
<ItemStyle CssClass="myGridItemMaxWidth" HorizontalAlign="Right" Wrap="false" />
</asp:BoundField>
<asp:CheckBoxField DataField="Cntc_Allowed_To_Edit" HeaderText="?Allowed" SortExpression="Cntc_Allowed_To_Edit" />
</Columns>
<HeaderStyle CssClass="my_Grid_Header" />
<SelectedRowStyle BackColor="#669999" ForeColor="White" Font-Bold="True" />
</asp:GridView>
后面的代码:
protected void grv_Contacts_RowCommand(object sender, GridViewCommandEventArgs e)
{
int my_Grv_Row_Index = Convert.ToInt32(e.CommandArgument);
CheckBox my_CBX = (CheckBox)(grv_Contacts.Rows[my_Grv_Row_Index].Cells[3].Controls[0]);
lbl_Message.Text = my_CBX.Text;
}
我在 lbl_Message.Text 中不断得到 NULL
我在 my_CBX 上调试并添加了一个手表,它显示了它的
值为:{Text = "" Checked = true}
那么 - 如果网格视图中的复选框被选中,我如何评估它...?
谢谢!
【问题讨论】:
标签: c# asp.net gridview checkbox evaluate