Click here to Skip to main content
12,948,567 members (62,198 online)
Rate this:
Please Sign up or sign in to 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
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
Updated 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 ?
[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!!!!!!
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
Top Experts
Last 24hrsThis month
OriginalGriff 5,419
CHill60 3,275
Maciej Los 2,778
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
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