I have a dropdownlist("ddlTemplate") control and a gridview("gvPlanning") control with 1 BoundField column, 1 TemplateField column and remaining columns will be generated dynamically from database.In TemplateFiled Column i have 3 image buttons viz: Edit,
update and cancel.
Gridview will be populated based on the selecteditem of dropdownlist.
if i click on edit imagebutton, i need to add textboxes dynamically in all the columns of that row except first 2 column. And if i click on Update imagebutton i need to retrieve the textbox values.
we can add template field column for textboxes also, but why i am sticking to this method is.. the number of columns changes depending on the selecteditem from the dropdownlist. Eg: If i select india from dropdownlist the number of columns in the gridview
would be 4 and if i select UK from dropdownlist the number of columns would be 9 likewise.
Please help me and thanks in advance..
Please Mark as Answer if this post is helpful
Regards,
Haritha Kakarla
If you set EditIndex and DataBind, the AutoGenerated BoundFields for that Row will go into Edit mode. That's done with TextBoxes.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Marked as answer by haritha.kakarla on Mar 28, 2011 10:14 AM
In the event of clicking update button you can get the edit row and access the TextBox in that row and get its text. I suppose you handle the RowUpdating event when you click Update button. Then do this:
TextBox tb = (TextBox)GridView1.Rows[GridView1.EditIndex].FindCotnrol("TextBox1");
string var = tb.Text;
No matter you use template or dynamic column, just give the control id to find the TextBox. If you don't know the id, just access the first control in the cell: (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[0].Controls[0]
Thank you very much for the reply.. i got the answer and i am facing one more problem here. In my gridview the columns are generated automatically. Now, I need to disable editing option in certain columns in the RowEditing Event. Please let me know how to
disable.
Many thanks in advance...........
Please Mark as Answer if this post is helpful
Regards,
Haritha Kakarla
haritha.kaka...
Member
131 Points
116 Posts
Create Textbox dynamically in GridView and retrieve the value in button click event
Mar 24, 2011 07:31 AM|LINK
Hi friends,
I have a dropdownlist("ddlTemplate") control and a gridview("gvPlanning") control with 1 BoundField column, 1 TemplateField column and remaining columns will be generated dynamically from database.In TemplateFiled Column i have 3 image buttons viz: Edit, update and cancel.
Gridview will be populated based on the selecteditem of dropdownlist.
if i click on edit imagebutton, i need to add textboxes dynamically in all the columns of that row except first 2 column. And if i click on Update imagebutton i need to retrieve the textbox values.
we can add template field column for textboxes also, but why i am sticking to this method is.. the number of columns changes depending on the selecteditem from the dropdownlist. Eg: If i select india from dropdownlist the number of columns in the gridview would be 4 and if i select UK from dropdownlist the number of columns would be 9 likewise.
Please help me and thanks in advance..
Regards,
Haritha Kakarla
superguppie
All-Star
48225 Points
8679 Posts
Re: Create Textbox dynamically in GridView and retrieve the value in button click event
Mar 24, 2011 10:36 AM|LINK
If you set EditIndex and DataBind, the AutoGenerated BoundFields for that Row will go into Edit mode. That's done with TextBoxes.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
haritha.kaka...
Member
131 Points
116 Posts
Re: Create Textbox dynamically in GridView and retrieve the value in button click event
Mar 28, 2011 05:22 AM|LINK
Hi,
Thank you for the response. My doubt here is, how to retrieve data from these textboxes on postback.
Thanks in advance.
Regards,
Haritha Kakarla
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Create Textbox dynamically in GridView and retrieve the value in button click event
Mar 28, 2011 07:37 AM|LINK
Hi,
In the event of clicking update button you can get the edit row and access the TextBox in that row and get its text. I suppose you handle the RowUpdating event when you click Update button. Then do this:
TextBox tb = (TextBox)GridView1.Rows[GridView1.EditIndex].FindCotnrol("TextBox1");
string var = tb.Text;
No matter you use template or dynamic column, just give the control id to find the TextBox. If you don't know the id, just access the first control in the cell: (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[0].Controls[0]
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
haritha.kaka...
Member
131 Points
116 Posts
Re: Create Textbox dynamically in GridView and retrieve the value in button click event
Mar 28, 2011 09:01 AM|LINK
Thank you very much for the reply.. i got the answer and i am facing one more problem here. In my gridview the columns are generated automatically. Now, I need to disable editing option in certain columns in the RowEditing Event. Please let me know how to disable.
Many thanks in advance...........
Regards,
Haritha Kakarla
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Create Textbox dynamically in GridView and retrieve the value in button click event
Mar 30, 2011 01:22 AM|LINK
Hi,
For further question, please start a new thread.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework