问题描述
//更新protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse){//将AdminID单元格设置为不可修改(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]asTextBox).Enabled=false;//#1//获取各个值stringadminID=GridView1.DataKeys[e.RowIndex].Value.ToString();stringtitle=(GridView1.Rows[e.RowIndex].Cells[1].Controls[0]asTextBox).Text;stringnavigateurl=(GridView1.Rows[e.RowIndex].Cells[2].Controls[0]asTextBox).Text;stringdescription=(GridView1.Rows[e.RowIndex].Cells[3].Controls[0]asTextBox).Text;}//#1有问题,我想禁用,可这样写还是不能禁用,请指教一下。
解决方案
解决方案二:
如果是用.new生成的列的话里面有个属性ReadOnly,是否能进行编辑
解决方案三:
贴一下.aspx的代码<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="AdminID"OnRowCancelingEdit="GridView1_RowCancelingEdit"OnRowEditing="GridView1_RowEditing"OnRowUpdating="GridView1_RowUpdating"><Columns><asp:BoundFieldDataField="AdminID"HeaderText="ID"/><asp:BoundFieldDataField="Title"HeaderText="标题"/><asp:BoundFieldDataField="NavigateUrl"HeaderText="导航页面"/><asp:BoundFieldDataField="Description"HeaderText="描述信息"/><asp:CommandFieldShowEditButton="True"/><asp:CommandFieldShowDeleteButton="True"/></Columns></asp:GridView>
解决方案四:
findcontrol
解决方案五:
RowEditing中处理,而不是在Updating中,后者是已经提交更新的时候发生
解决方案六:
protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse){//将AdminID单元格设置为不可修改(GridView1.Rows[e.NewEditIndex].Cells[0].Controls[0]asTextBox).Enabled=false;//#1}
解决方案七:
这样写也不行啊//编辑protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse){//将AdminID单元格设置为不可修改GridView1.Rows[e.NewEditIndex].Cells[0].Enabled=false;GridView1.EditIndex=e.NewEditIndex;Bind();}
解决方案八:
(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]asTextBox).ReadOnly=true;????????