Gridview中 在 编辑 列 想让某一行的的某一列的控件为隐藏,怎么实现?
我想实现。如果该行的编号为1,那么这一行的DDL控件不显示。通过查找该行的num列的值来判断编号。。
我是用RowCreat实现。不过这个事件中居然只能找到 DDL控件,其他2个找不到?
请问为什么?
还有其他方法么?
//绑定下拉框
protected void GridView_onRowCreat(object sender,GridViewRowEventArgs e)
{
if ((e.Row.RowState&DataControlRowState.Edit) == DataControlRowState.Edit)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ "databaseConnectionString "].ToString());
SqlCommand cmd = new SqlCommand( "select [num],LEFT(ColumnName,8) AS ColumnName from [ArticleColumn] ", conn);
conn.Open();
//DDL列模板有DDL和隐藏域2个控件
DropDownList DropDownList_Edit = (DropDownList)e.Row.Cells[3].FindControl( "DropDownList_Edit ");
HiddenField HiddenField_one = (HiddenField)e.Row.Cells[4].FindControl( "HiddenField_one ");
//ddl数据源绑定
SqlDataAdapter myadapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
myadapter.Fill(ds, "AritcleColumn ");
DropDownList_Edit.DataSource = ds;
DropDownList_Edit.DataTextField = "ColumnName ";
DropDownList_Edit.DataValueField = "num ";
DropDownList_Edit.DataBind();
DropDownList_Edit.SelectedItem.Value = HiddenField_one.Value;
//找到该行的编号列的值
Label label_num = (Label)e.Row.Cells[0].FindControl( "Label_num ");
if (label_num.Text == "1 ")
{
&n