views:

490

answers:

3

Hello,

I have made a one form with functionality to create grid view dynamically.

i have used concept of "how to create template columns dynamically in a grid view"

Link : http://www.codeproject.com/KB/aspnet/DynamicTemplateColumn.aspx

its working good.

i am creating control run time set the different property of control and bind it to gridview columns.

For example if i want to add text box column into gridview, then i create text box, set the different property of text box, and add that template to gridview column.

But the problem is , once page datagrid load with textbox column, i am enter some data in that column.

then click on save button on page. when i clicked on save then after postback i am not able to get data of that text box column.

For Example

1) Load gridview with Text Box Column (Added runtime)

2) Added one row in Datagridview

2) Write data in that column(Text box column)

3) Click Save button (to save data of gridview)

4) Page post back (Here Gridview has no rows!!!)

It shows row count 0 when page post back!

So How to get value of that text box column?

I need your Help.

Prompt reply will be appreciated.

Thank you

+1  A: 

Be sure to access the page at the correct time. If you access it in the OnInit event, the ViewState will not have been mapped back on your grid.

PageLoad would be appropriate probably.

Juri
Hello, Thanks for the replyBut i have checked grdiview status on Page Init and Page load .but i am getting the same (0 rows).even i have explicitly enable view stat of gridview and the controls that i am adding into gridview column dynamically.
Dhruval Shah
are you sure that the ViewState is enabled. Should be a property on the page "EnableViewstate=true" or on the control directly. Check that.
Juri
Thank you Very much for your suggetions.I have got the answer. I had forgot the life cycle of asp.net. i have got that data in "PreRender" and "Unload" event of gridview.Thanks again for your participation. :)
Dhruval Shah
A: 

Seems to me like it is not being added to the viewstate, is there any way that you can add it in?

Or, as Juri mentioned, the viewstate is not populated, do the other controls have values?

Edit: Maybe it is not being added to the page's Controls collection - can you see if it is in there?

Fiona Holder
Hello, Thanks for the replyBut i have checked grdiview status on Page Init and Page load .but i am getting the same (0 rows).even i have explicitly enable view stat of gridview and the controls that i am adding into gridview column dynamically.
Dhruval Shah
If you are using the code sample that you have linked, it seems to be creating the controls to the DynamicTemplate here: mt.AddControl(t1, "Text", "Sno");I suspect that you need to add it into the page's Controls to get it in the postback
Fiona Holder
Thank you Verymuch for helping me. :)I have got the answer. I forgot the life cycle of asp.net. i have got that data in "PreRender" and "Unload" event.Thanks again for your participation. :)
Dhruval Shah
A: 

I had forgot the life cycle of asp.net. i have got that data in "PreRender" and "Unload" event of gridview, from where i can store it else where.

Dhruval Shah
which btw was my hint ;)
Juri