在gridveiw中源为:
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ntc_id" />
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ntc_title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ntc_title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="substr(ntc_content,1,20)"/>
<asp:BoundField DataField="ntc_publishdate"/>
</Columns>
后台为:
protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{ int ntc_id = Convert.ToInt32(((TextBox)(GV.Rows[e.RowIndex].Cells[2].Controls[0])).Text);
string Title = ((TextBox)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text;
string Content = ((TextBox)(GV.Rows[e.RowIndex].Cells[4].Controls[0])).Text;
string Date = ((TextBox)(GV.Rows[e.RowIndex].Cells[5].Controls[0])).Text;
command.CommandText = "update th_notice set ntc_title='" +e.NewValues+ "',ntc_content='" + Content + "',ntc_operator='" + "aaa" + "',ntc_publishdate='" + Date + "' where ntc_id='" + ntc_id + "'";
command.ExecuteNonQuery();
GV.EditIndex = -1;
GetGVData();
}
不加验证控件之前,编辑后正确更新,当加入验证控件后,提示无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”,我将((TextBox)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text改为((Label)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text还是不正确,请大侠帮忙,已经困扰我好久啦。
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ntc_id" />
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ntc_title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ntc_title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="substr(ntc_content,1,20)"/>
<asp:BoundField DataField="ntc_publishdate"/>
</Columns>
后台为:
protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{ int ntc_id = Convert.ToInt32(((TextBox)(GV.Rows[e.RowIndex].Cells[2].Controls[0])).Text);
string Title = ((TextBox)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text;
string Content = ((TextBox)(GV.Rows[e.RowIndex].Cells[4].Controls[0])).Text;
string Date = ((TextBox)(GV.Rows[e.RowIndex].Cells[5].Controls[0])).Text;
command.CommandText = "update th_notice set ntc_title='" +e.NewValues+ "',ntc_content='" + Content + "',ntc_operator='" + "aaa" + "',ntc_publishdate='" + Date + "' where ntc_id='" + ntc_id + "'";
command.ExecuteNonQuery();
GV.EditIndex = -1;
GetGVData();
}
不加验证控件之前,编辑后正确更新,当加入验证控件后,提示无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”,我将((TextBox)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text改为((Label)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text还是不正确,请大侠帮忙,已经困扰我好久啦。
解决方案 »
- 求助:Unable to load DLL 'OraOps9.dll': Access is denied
- 关于menu的问题
- 请大家帮忙:如何用ASP做登陆时的验证码?原理是什么呢?谢谢大家!
- 水晶报表的多表显示问题,整了一天了。。。
- datagrid绑定了数据,想通过一个字段来控制某一行数据show出来是组体或者不同颜色
- 网站上传以后遇到问题,请高人指点。万分感谢!!
- dsoframer 保存docx不行, doc可以,高手帮忙看下
- 用.NET做的Web Service,EnableSession设为了true,web service的登录基于Form,现在用asp调用有一点不清楚
- 在DetailsView添加数据后,怎么返回信息?
- ***紧急呼叫: 我的程序在本机上测试正常,可放到web只装有.net框架的服务器上 无法连接到数据服务器? 在线等...
- 如何获取数据表列的所有值????????
- ASP.NET高手进来看看,这个数据库插入操作,哪儿出问题了?
string Title = ((TextBox)(GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text; 改成string Title=(GV.Rows[e.RowIndex].FindControl("TextBox1") as TextBox).Text;