I have created a gridview and added column dynamically in code behind.
for blank rows I have added textbox with same id.
But I am unable to get those text boxes value and getting error
"
Multiple controls with the same ID 'txt' were found. FindControl requires that controls have unique IDs
"
Sunny SharmaRank #223 · 11.1K pointsPosted Sep 29, 2013, 11:08 PM EDT
The error is self explanatory as it says there can not be Multiple controls with the same ID.
Please refer to this post on how to do it and how to get the control's value back using FindControl:
http://www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx
Hope it helps :)
shibasankar behera64 pointsPosted Sep 29, 2013, 11:12 PM EDT
Actually I have created Gridview according to database items and all total is doing in code behind. I dont know how many columns are there. SO I want to assign textbox in gridview according to column numbers.
Sunny SharmaRank #223 · 11.1K pointsPosted Sep 30, 2013, 12:35 AM EDT
shibasankar behera64 pointsPosted Sep 30, 2013, 12:42 AM EDT
Here I am getting conditions for specific RFQRef_No, and adding those conditions as columns in gridview. Different RFQRef_No contains different number of conditions.
so after binding I am adding textbox for those conditions.
Prashant Srivastava87 pointsPosted Oct 5, 2013, 4:54 AM EDT
You are getting this error because you are assigne the same ID to 2 controls which logically wrong because in this way it will hard to predict for which control you want to work.
SOLUTION STEPS :
1. Change the id of the textbox control in .aspx.
2. Create a RowDataBound Event.
3. Find textbox in RowDataBound using FindControl (reason : on run time id of control will be changed and it will hard to know for which row of textbox you want to work).
4. Once you will get the control (via FindControl) you can do any thing.
Regards,
Prashant Srivastava
shibasankar behera64 pointsPosted Oct 6, 2013, 9:10 PM EDT
I am adding columns to grid view dynamically according to need from database. There are no fixed number of columns, so how shall I give id to them. So I am simply adding text boxes to those columns and want to get values. Also I am getting values from those text boxes by this process in one of my demo page. But when I am implementing this concept in my main project it is nit working.
If you wish I can send you code.
Thank you for your time and consideration towards me.
Prashant Srivastava87 pointsPosted Oct 7, 2013, 7:19 AM EDT
Please send me your code. Let have a look.
shibasankar behera64 pointsPosted Oct 7, 2013, 9:36 PM EDT
//here my operations....
}