Hi. First I'd like to mention that I've spent several days of searching all forums and reading tons of stuff on the subject. I've also spent a significant amount of time in debug mode banging my head against the screen without success in finding the solution. With that out of the way. My problem is as follows. I have a custom GridView control where I generate the Template fields for each column. I'm using someone elses class that extends the Itemplate and returns labels for ItemTemplate, and TextBoxes for EditTemplate.

I need this in order to implement bulk edit for the gridview where users press button Edit and all fields become textboxes, they can then change the values, and click Update button at which point I need to be able to retrieve the values from the TextBoxes in these Template Fields.

What I have tried thus far: when user clicks Edit button, my dynamic code builds the columns and specifies that the Template field is an EditTemplate, it then adds these columns to the grid view. The gridview shows the textboxes with all values retrieved from sqldatasource.

When I press the Update button, the page does a postback, as I can see Page_Load event fire, I check for a flag that I previously set when the Edit button was pressed (I store it's value in View State) and call the Update method.

In it I iterate through the gridview rows collection, check that the RowType of each row is DataRow and call GridView.UpdateRow(i, false), passing each rows index to the UpdateRow method.

At this point I have tried everything I can to find the values stored in the textboxes, but I cannot find any of the textbox controls.

I've tried using the current row's FindControl method and specifying the name of the textbox field,

I've tried using Request.Params method where I can tried passing the client id, as it seen in the View Source of the page such as this

Request.Params["grid1$gvData$ctl02$MMCODE"]

Still no luck, I've tried going up an down the Row's cells, controls collections, it seem to list the counts for rows correctly, the same goes for the amount of cells for each row, but at no point was I able to actually locate any controls such as textboxes or anything else and retrieve any values from them.

I'm really stuck and I'm on a deadline and this is really killing me. Any help is appreciated, if you need me to post some source code I can, but I think I described the situation clearly!


Thanks in advance!!!

have you tried

private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
	{
		
        string yourTextValue = ((TextBox)e.Item.Cells[1].Controls[1]).Text;


	}

I'll try it and let you know, but I'm not sure at what point this event would fire.
I'm assuming I need to wire it up in my gridview definition as well?

try adding this to your code

#region Web Form Designer generated code
	override protected void OnInit(EventArgs e)
	{

		InitializeComponent();
		
		this.DataGrid1.UpdateCommand+=new DataGridCommandEventHandler(DataGrid1_UpdateCommand);

		base.OnInit(e);
	}

	private void InitializeComponent()
	{    

	}
	#endregion
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.