How to retrive dynamic dropdownlist data insde the dynamic gridview

Posted by Mahesh_Chs under ASP.NET on 1/9/2013 | Points: 10 | Views : 1734 | Status : [Member] | Replies : 1

i have added columns to the gridview like this dynamically

BoundField bField = new BoundField();
bField.HeaderText = Label6.Text;

for to get dropdownlist inside the gridview i have written code like this in GridView2_RowCreated event

TableCell tc = new TableCell();
DropDownList ddlnewList = new DropDownList();

for to get the selected value from dropdownlist i have written like this in button_Clkick event
if (r.RowType == DataControlRowType.DataRow)
foreach (GridViewRow r in GridView2.Rows)
DropDownList box1 = (DropDownList)GridView2.Rows[i].Cells[1].FindControl("ddlnewList");
string s= box1.SelectedItem.Text;

but i am getting null value at box1

Thanks in advance..


Posted by: Nisar87 on: 1/14/2013 [Member] Starter | Points: 25

try like this
foreach (GridViewRow row in GridView2.Rows)

DropDownList box1 = new DropDownList();
box1 = (DropDownList)row.FindControl("ddlnewList");
string s= box1 .SelectedItem.Text;

Nisar Ahmad

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response