how to get values from textbox which is in gridview Footer c#?

后端 未结 1 1534
悲哀的现实
悲哀的现实 2021-01-22 06:59

like in title + how to handle button click which button is in GridView Footer also?

file .aspx seems like this



        
1条回答
  •  抹茶落季
    2021-01-22 07:45

    Inside your GridView_RowCommand Event you can access the footer control by GridView1.FooterRow.FindControl method.

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert", StringComparison.OrdinalIgnoreCase))
        {
            TextBox txtSomeNewValue = ((TextBox)GridView1.FooterRow.FindControl("txtSomeNewValue"));
            string theTextValue = txtSomeNewValue.Text;
        }
    }
    

    Update: wrapped the code in an if block that checks if the commandname is what you were expecting. This event is also used for delete, edit, etc, so you might end up running the code for an event you didnt intend if you dont wrap it in this.

    0 讨论(0)
提交回复
热议问题