路过的都进来帮忙看下。关于gridview中取值问题
protected void my_textchanged(object sender, EventArgs e){
TextBox txt = sender as TextBox;
GridViewRow row = txt.NamingContainer as GridViewRow;
int index = row.RowIndex;
TextBox tbx = GridView1.Rows[index].Cells[3].FindControl("TextBox2") as TextBox;//获取数量
int amount = Convert.ToInt16(tbx.Text.ToString());
string tbx8 = ((Label)GridView1.Rows[index].FindControl("Label8")).Text;//获取价格
//string chicun = ((Label)GridView1.Rows[index].FindControl("Label6")).Text;//尺寸
}
为什么用这样的方法前面的数量与价格可以取的到,但尺寸及其他列的值都取不出来。。为什么,我这是在gridview模板中
<asp:TemplateField HeaderText="购买价格" SortExpression="购买价格">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("购买价格") %>' ></asp:TextBox>
</EditItemTemplate>
<ItemStyle Width="100px" CssClass="cs2" />
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("购买价格") %>' Font-Size="12px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="购买数量" SortExpression="购买数量">
<ItemStyle CssClass="cs2" />
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("购买数量") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Width="30px" Height="20px" Text='<%# Bind("购买数量") %>' autopostback="true" OnTextChanged ="my_textchanged" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="购买尺码" SortExpression="购买尺码" >
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("购买尺码") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("购买尺码") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="购买颜色" SortExpression="购买颜色" >
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("购买颜色") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("购买颜色") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
大家帮忙看看啊