Hi
I have below code . Textbox is added at the end. Now i want to read its value in all Gridview rows
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for(int i =0; i < e.Row.Cells.Count; i++)
{
TextBox txt = new TextBox();
txt.Text = e.Row.Cells[i].Text;
e.Row.Cells[i].Text = "";
e.Row.Cells[i].Controls.Add(txt);
}
}
}
Thanks
Ramco RamcoPosted May 5, 2023, 1:12 PM
Hi Brahma
On click of button i am looping thru all records. I have no Edit/Cancel/Update option
Secondly in Page Source it is showing like this - id="grdPlanning_txtSessionDateSystem.Web.UI.WebControls.GridViewRow_108"
Thanks
Brahma Prakash ShuklaPosted May 5, 2023, 12:43 PM
To read the value of the dynamically created TextBox in each row of the GridView, you can modify your code as follows:
Then, to read the value of the TextBox in each row, you can handle the GridView's RowCommand or RowUpdating event. Here's an example of how you can do this in the RowCommand event:
In this example, we assume that you have a button in each row of the GridView with the CommandName "UpdateRow" and the CommandArgument set to the row index. When the button is clicked, the RowCommand event is fired, and the value of each TextBox in the clicked row can be read and processed as needed.