How to retrive dynamic dropdownlist data insde the dynamic gridview

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

i have added columns to the gridview like this dynamically

BoundField bField = new BoundField();
bField.HeaderText = Label6.Text;
GridView2.Columns.Add(bField);

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();
e.Row.Cells.Add(tc);

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..




Responses

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

Up
0
Down
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
http://www.dotnetobject.com/

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

Login to post response