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
"
shibasankar beheraPosted Oct 8, 2013, 1:36 AM
//here my operations....
}
Prashant SrivastavaPosted Oct 7, 2013, 11:19 AM
Please send me your code. Let have a look.
shibasankar beheraPosted Oct 7, 2013, 1:10 AM
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 SrivastavaPosted Oct 5, 2013, 8:54 AM
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 beheraPosted Sep 30, 2013, 4:42 AM
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.
Sunny SharmaPosted Sep 30, 2013, 4:35 AM
shibasankar beheraPosted Sep 30, 2013, 3:12 AM
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 SharmaPosted Sep 30, 2013, 3:08 AM
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 :)