Last post Mar 30, 2011 01:22 AM by Qin Dian Tang - MSFT
Mar 24, 2011 07:31 AM|haritha.kakarla|LINK
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..
Mar 24, 2011 10:36 AM|superguppie|LINK
If you set EditIndex and DataBind, the AutoGenerated BoundFields for that Row will go into Edit mode. That's done with TextBoxes.
Mar 28, 2011 05:22 AM|haritha.kakarla|LINK
Thank you for the response. My doubt here is, how to retrieve data from these textboxes on postback.
Thanks in advance.
Mar 28, 2011 07:37 AM|Qin Dian Tang - MSFT|LINK
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.Controls
Mar 28, 2011 09:01 AM|haritha.kakarla|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
Many thanks in advance...........
Mar 30, 2011 01:22 AM|Qin Dian Tang - MSFT|LINK
For further question, please start a new thread.