如何在gridview中动态添加文本框上触发textboxchanged事件

时间:2016-09-02 13:39:53

标签: c# asp.net

在我的项目中,我可以动态地在gridview中添加n个文本框。我的问题是,如果用户在gridview的任何一行中更改任何文本框的文本,我想激活textboxchanged事件。

HTML CODE:

 <asp:GridView ID="GridView1" runat="server" 
    Width="907px" style="text-align: center" CellPadding="4" ForeColor="#333333" 
                GridLines="None" onrowdatabound="GridView1_RowDataBound"> 
</asp:GridView> 

在GRIDVIEW中添加列:

 foreach (string a in crcl)
            {
                SqlCommand cmd1 = new SqlCommand("select qty from purchaseinstruction where project ='" + DropDownList1.SelectedItem.ToString() + "' AND circle = '" + a + "' AND item = 'BIFURCATION' AND material = '" + mat + "'", agr);
                SqlDataReader dr1 = cmd1.ExecuteReader();
                if (dr1.Read())
                {
                    string val = dr1[0].ToString();
                    if (val.Length > 0)
                    {
                        row[a] = val;
                    }
                    else
                    {
                        row[a] = 0;
                    }
                }
                else
                {
                    row[a] = 0;
                }
                dr1.Dispose();
            }
            dt.Rows.Add(row);
 GridView1.DataSource = dt;
        GridView1.DataBind();

在ROWBOUND上添加文本框:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    int i = 3;
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        crcl = (List<string>)ViewState["bdi2"];
        foreach(string a in crcl)
        {
            TextBox TextBox101 = new TextBox();
            TextBox101.ID=a;
            TextBox101.Width = 60;
            TextBox101.Text = (e.Row.DataItem as DataRowView).Row[a].ToString();
            TextBox101.AutoPostBack = true;                
            e.Row.Cells[i].Controls.Add(TextBox101);
            i++;
        }
    }
}

这里我有三个问题  1.回发文本框后进行处理  2.如何保留textboxchange的文本框值?  3.如何知道哪个文本框触发textboxchange

0 个答案:

没有答案