GridView 中放textbox 问题
我在GridView 里放了个textbox 控件并加了 ontextchanged="TextBox1_TextChanged"
接下来如何获取 textbox1 里的值呢?
代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="Table-00" Width="100%" CellSpacing="1"
DataKeyNames="Id" onrowcommand="GridView1_RowCommand"
onrowdatabound="GridView1_RowDataBound" CellPadding="4" ForeColor="#333333" GridLines="None"
>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="信息名称">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("titles") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="排序">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" ontextchanged="TextBox1_TextChanged" text='<%#Eval("sort") %>'></asp:TextBox> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除操作">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" Width="15px" Height="15px" ImageUrl="../images/d.ico" CommandName="ImageButton1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="修改/查看">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" CommandName="ImageButton2" Width="15px" Height="15px" ImageUrl="../images/u.ico" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
我是想改变了 textbox 的值后,ontextchanged="TextBox1_TextChanged" 就直接更新 数据库里的数据
[解决办法]
参考:
string newAssortmentOneName = ((TextBox)(gvAssortment.Rows[e.RowIndex].Cells[1].FindControl("txtAssortmentOneName"))).Text.ToString().Trim();
[解决办法]
在GridView1_RowDataBound事件方法里:
if(e.Row.RowIndex>-1)
{
TextBox tb=e.Row.FindControl("TextBox1") as TextBox;
}