Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ear sir,

I have created dynamic columns for gridview. In that gridview every cell containing two dropdown list. one is for lecturer name with id. and another one is subject name.

My problem is how to retrive data from dynamic gridview and store into database.

I am using my code sample is given below
C#
foreach (GridViewRow r in GridView2.Rows)
{
  for (int i = 1; i < GridView2.Rows.Count; i++)
  {
    if (r.RowType == DataControlRowType.DataRow)
    {
      string box = r.Cells[1].Text;
      DropDownList box1 = DropDownList)GridView2.Rows[i].Cells[0].FindControl("ddlnewList");
    }
}

Please help me..

/Edit Code block added Jibesh /Edit
Posted
Updated 8-Jan-13 20:46pm
v2

1 solution

What do you mean by dynamic ? Your code looks like a viable way to iterate over this sort of data. Personally, I'd avoid this sort of messiness and get the data through AJAX and send it to save via an AJAX call.

You need to tell us what is going wrong with the code you posted, if you want us to help you make it work. What is happening ? What do you mean by 'dynamic' ? How is this gridview created ?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jan-13 21:16pm    
[OP asked (in the "solution", removed):]

Dynamic in the sense i created headers by code way rather than using databound or itemtemplate and had added table cells to that created gridview how can i retrive data from that gridview......containing dropdownlists in that table cells!!!!!!
Sergey Alexandrovich Kryukov 8-Jan-13 21:18pm    
I have no idea why OP considers "databound" as "not dynamic". Reflects new "developers'" thinking: the code I don't see is not dynamic, not run time. :-)
—SA

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