Click here to Skip to main content
11,639,861 members (65,482 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
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
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 8-Jan-13 11:22am
Edited 8-Jan-13 20:46pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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 ?
Sergey Alexandrovich Kryukov at 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 at 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. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Suvendu Shekhar Giri 330
1 CPallini 177
2 F-ES Sitecore 170
3 sasanka sekhar panda 155
4 142
0 OriginalGriff 9,081
1 Sergey Alexandrovich Kryukov 8,847
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,650
4 F-ES Sitecore 2,558

Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100