Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
GridView dynamic column with editable, i am creating a grid which is dynamic and can be update and delete record, In the the of bind grid i use Edititemtemplate for bind textboxes with ID in it. when click on edit button.

in rowupdating event i am unable to get old and new values of textboxes for update record.

What I have tried:

Dim name As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txt_Name"), TextBox)


Here txt_name is ID of textbox.

but not working
Posted
Comments
an0ther1 19-May-16 1:50am    
Ensure you have a valid RowIndex
And try using a GridViewRow as follows;
Dim gvrEdit as GridViewRow = gridView1.Rows(e.RowIndex)
Dim txtBox as TextBox = DirectCast(gvrEdit.FindControl("txt_Name"), textBox)
Additionally, ensure that in your RowEditing event handler make sure you set the gridView1.EditIndex

Kind Regards
Member 11449483 19-May-16 2:00am    
yes i set GridView1.editindex but not fetch value
i am using this artical for creating dynamic grid.
in itemtemplate i have use some code for put textbox id for fetching data
when textbox object create in ListItemType.Item
then tb1.ID=_columnNAme
but not get data by textbox id
http://www.codeproject.com/Articles/13462/How-to-create-template-columns-dynamically-in-a-gr#_articleTop

Thanks
Member 11449483 19-May-16 2:08am    
Same problem in code project please solve this.
http://www.codeproject.com/Questions/469944/how-to-get-value-of-dynamic-created-textbox-in-ite
an0ther1 19-May-16 18:46pm    
Please always reply to a comment as the author receives a notification.
If FindControl does not return your control then the ID you are using is incorrect. If you load the page in a browser window & then view the source you can see what the actual control's ID is.
Alternatively use your debugger, in your RowUpdating event handler get the GridViewRow & look at what controls it contains using the "Locals" window.
This should allow you to identify the actual controls that are contained on your row

Kind Regards
Member 11449483 20-May-16 0:33am    
now it is working, in dynamic template grid view , grid lose it's currentstate and not able to find textboxex. i have use griddatabind() on pageload() then it can find the textbox using ID.

but one problem occur :
the page load event gets fires, but it just skips the SelectedIndexChanged event for the dropdown how to resolve this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900