GridView中TextBox失去焦点或文本改变时更新本行(获取本行某列的值)

来源:互联网 发布:决胜网seo 编辑:程序博客网 时间:2024/05/17 01:10
GridView中TextBox失去焦点或文本改变时更新本行(获取本行某列的值)
2011-06-16 0:21

本是小问题 ,记录以便以后使用,也希望给遇到该问题的同志提供方便,呵呵。

aspx:

<asp:GridView ID="gvDataList" runat="server" >

<Columns>

<asp:TemplateField HeaderText="就获取这列值吧">
<ItemTemplate>
<asp:Label ID="lblCartID" runat="server" Text='<%# Eval("CartID") %>'></asp:Label>

<ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="就通过这个文本框更新吧">
<ItemTemplate>
<asp:TextBox ID="txtWareNum" runat="server" Text='<%# Bind("ShopWareNum") %>' AutoPostBack="true" OnTextChanged="txtWareNum_TextChanged" ></asp:TextBox>

<ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView >

aspx.cs:

protected void txtWareNum_TextChanged(object sender, EventArgs e)
{
TextBox t = (TextBox)sender;
GridViewRow drv = (GridViewRow)t.NamingContainer;
int rowIndex = drv.RowIndex;
string cartid = ((Label)gvDataList.Rows[drv.RowIndex].FindControl("lblCartID")).Text;//这个就获取到了

//可根据这个值来进行操作了
}

原创粉丝点击