Click here to Skip to main content
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 12:22pm
Edited 8-Jan-13 21: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 OriginalGriff 440
1 Sergey Alexandrovich Kryukov 424
2 CPallini 210
3 King Fisher 209
4 CHill60 180
0 Sascha Lefévre 75
1 OriginalGriff 70
2 F-ES Sitecore 55
3 Peter Leow 50
4 Dave Kreskowiak 40

Advertise | Privacy | Mobile
Web03 | 2.8.150327.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