我有一个GridView
<EditItemTemplate>
<asp:CheckBox ID="CheckBox" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox_CheckedChanged" />
</EditItemTemplate>
结果始终相同,返回NULL。我的问题是找不到控制端插入Visible colum true / false。
答案 0 :(得分:3)
protected void grdPractices_OnRowEditing(object sender, GridViewEditEventArgs e)
{
this.grdPractices.EditIndex = e.NewEditIndex;
var vCheckBox = this.grdPractices.Rows[e.NewEditIndex].Controls[0].FindControl("chkSites") as CheckBox;
if (vCheckBox == null)
{
return;
}
}
<强>更新强>
在OnRowEditing事件中,您可以获取gridview要编辑的行的索引。然后使用索引,您可以找到对复选框的控制。验证复选框varible为null或执行任何操作。
答案 1 :(得分:1)
var chk = (CheckBox)(e.item.FindControl("CheckBox"))
此代码将返回您的复选框控件。
答案 2 :(得分:0)
在PostBack上你可以这样得到它:
protected void CheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkbox = (CheckBox)sender;
//now its available for you
}
在RowCommand上得到它(假设你的命令按钮是LinkButon):
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow grd = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int rowindex = grd.RowIndex;
CheckBox chkbox = (CheckBox)grd.Rows[rowindex].FindControl("checkboxId");
// do whatever
}
答案 3 :(得分:0)
protected void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
{
GridViewRow row = GridView1.Rows[e.NewEditIndex];
bool IsChecked = ((CheckBox)(row.Cells[0].FindControl("chkbox"))).Checked;
}