读书人

C#获取Gridwiew里面textbox的值,该怎么

发布时间: 2012-05-22 18:18:54 作者: rapoo

C#获取Gridwiew里面textbox的值
<asp:TemplateField HeaderText="确定操作">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
   
<asp:Button ID="btnEdit" CommandArgument='<%# Eval("ClsID") %>' runat="server"
Text="修改" onclick="btnEdit_Click" />

  
<asp:Button ID="btnDel" runat="server" CommandArgument='<%# Eval("ClsID") %>' Text="删除" />
</ItemTemplate>
</asp:TemplateField>.

我要在后台获取到textbox的值



后台我写的如下
int clsID = Convert.ToInt32(((Button)sender).CommandArgument);
string name = (gwNwsType.Rows[0].Cells[1].FindControl("txtNewsType") as TextBox).Text.Trim();
int orderby = Convert.ToInt32((gwNwsType.Rows[0].Cells[2].FindControl("txtPaiXu") as TextBox).Text.Trim());

if (newsService.Update_D_NewsType_ByClsID(clsID, name, orderby))
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "", "<script>alert('修改成功')</script>");
}
else
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "", "<script>alert('修改成功')</script>");
}
((Button)sender).Text = "修改";
(gwNwsType.Rows[0].Cells[1].FindControl("txtNewsType") as TextBox).ReadOnly = true;
(gwNwsType.Rows[0].Cells[2].FindControl("txtPaiXu") as TextBox).ReadOnly = true;



我只能获取到第一行的 我要动态控制他们,想控制那个都行 怎么写

[解决办法]
加个选中控件,循环判断
[解决办法]
Button.Parent.Parent as GridViewRow

C# code
 protected    void    GridView1_RowCommand(object    sender,    GridViewCommandEventArgs    e)      {              if    (e.CommandName    ==    "MyCommand")              {                      Button    btn    =    e.CommandSource    as    Button;                      GridViewRow    row    =    btn.Parent.Parent    as    GridViewRow;                      string    a    =    row.Cells[0].ToString();//获得第一个单元格的值              }      } 

读书人网 >asp.net

热点推荐