前台编辑以后,始终是提交编辑之前的值,就是下面的t1.Text总是取不到编辑以后的值
后台代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox t1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
TextBox t2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
SQLHelper sh = new SQLHelper();
sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2.Text.Trim() + "' WHERE 组编号 = " + t1.Text);
AlertInfo("修改成功");
GridView1.EditIndex = -1;
Bind(); }前台代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" CellPadding="3" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" OnRowEditing="GridView1_RowEditing" Width="100%" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit">
<Columns>
<asp:BoundField DataField="组编号" HeaderText="编号" />
<asp:BoundField DataField="组名" HeaderText="分类名称" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Update"
Text="更新"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="编辑"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" OnClientClick="return confirm('删除后不可恢复,确定删除吗?')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
后台代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox t1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
TextBox t2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
SQLHelper sh = new SQLHelper();
sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2.Text.Trim() + "' WHERE 组编号 = " + t1.Text);
AlertInfo("修改成功");
GridView1.EditIndex = -1;
Bind(); }前台代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" CellPadding="3" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" OnRowEditing="GridView1_RowEditing" Width="100%" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit">
<Columns>
<asp:BoundField DataField="组编号" HeaderText="编号" />
<asp:BoundField DataField="组名" HeaderText="分类名称" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Update"
Text="更新"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="编辑"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" OnClientClick="return confirm('删除后不可恢复,确定删除吗?')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
解决方案 »
- 只显示一条数据,后面的 学校以,号分割大虾们帮瞅瞅
- 想入门ASP.NET三层结构,希望高手推荐教材
- 取 textbox 中值的疑问
- WebServices异步调用的问题
- 触发按钮事件以后,网页的很多地方CSS样式没了?
- 北京.NET培训哪个好?
- 请问如何将HTML静态网页生成母版页
- 天涯论坛的图片访问权限控制是怎么处理的
- 无法从web项目中获取文件,无法打开web项目"webapplication1".... ,求教高手如何解决
- System.Web.UI.Collection
- 用微软的WebDeployment Project 编译出的网页为什么是乱码?该怎么样解决?
- Dataset 查询的问题?
{
TextBox t1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
int no = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
TextBox t2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
SQLHelper sh = new SQLHelper();
sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2.Text.Trim() + "' WHERE 组编号 = " + no.ToString());
AlertInfo("修改成功");
GridView1.EditIndex = -1;
Bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String t1 = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.Trim();
String t2 = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
SQLHelper sh = new SQLHelper();
sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2 + "' WHERE 组编号 = " + t1);
AlertInfo("修改成功");
GridView1.EditIndex = -1;
Bind(); }
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{......}
}