This is a migrated thread and some comments may be shown as answers.

[Solved] Added Text Box to Rad Grid does not persist during postback

2 Answers 309 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hammdo
Top achievements
Rank 1
hammdo asked on 28 Apr 2008, 04:25 PM
I've created a RadGrid and added a 'text box' to a bound column during the ItemDataBound event:

public void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

{

if (e.Item is GridDataItem)

{

add the text box...

TextBox txtBox =

new TextBox();

txtBox.ID =

"txtQty" + e.Item.ItemIndex.ToString();

txtBox.Attributes.Add(

"runat", "server");

e.Item.Cells[4].Controls.Add(txtBox);

}

}

Textbox adds fine, Shows up in grid, but when posted back, is not available in grid.  I'm not rebuilding the grid on postback since I don't want to loose the values. 

The grid is not in edit mode -- I need the text boxes on all rows so the user does not want to click 'edit' each time they want to add a value.  Upon postback, I want to read each row and check to see if the data is different than originally loaded.

What am I missing here?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2008, 07:38 AM
Hi hammdo,

Try adding the textbox in the RadGrid_ItemCreated event and assign the values in the itemdatabounf event.

Shinu.
0
hammdo
Top achievements
Rank 1
answered on 29 Apr 2008, 07:49 AM
Thanks for the suggestion.  I actually found a way to do it using an example from this post:

http://www.telerik.com/community/code-library/submission/b311D-gtcga.aspx

By creating a 'template' column, I was able to do exactly what I needed.  I had to check the fields 'before' the grid was re-created in the Page_OnLoad event since the grid will be 'rebuilt' (that is necessary when you're using sorting/grouping on the grid).

-Don
Tags
Grid
Asked by
hammdo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
hammdo
Top achievements
Rank 1
Share this question
or