dropdown box in gridview of asp.net with c#

Posted by Raghuldrag under C# on 3/27/2013 | Points: 10 | Views : 2255 | Status : [Member] | Replies : 2
Hai Friends,
i ve the fields of
Name:(textbox)
class:(dropdown box with option of 1..12)
if i m inserted the value ll display on gridview,i done that also while i m edit the row for making update the dropdown not shown the current selected value how to make code




Responses

Posted by: Jayakumars on: 3/27/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
try this Code
<asp:DropDownList ID="Drp1" runat ="server" DataTextField ="EmpId" DataValueField ="EmpName"></asp:DropDownList>
foreach (GridViewRow gv in Grd1.Rows)
{
DropDownList drp1 = (DropDownList)gv.FindControl("Drp1");
drp1.DataSource = ds;
drp1.DataTextField = "EmpName";
drp1.DataValueField = "EmpId";
drp1.DataBind();
}

Mark as Answer if its helpful to you

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

Posted by: aswinialuri-19361 on: 3/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

Try this i think it is useful to you
<EditItemTemplate>
<asp:DropDownList ID="dropDownDept" DataSource="<%# BindDropDownDepartment() %>" DataTextField="DeptName" DataValueField="DeptId" runat="server" SelectedValue='<%# Eval("DeptId").ToString() %>'>
</asp:DropDownList>
</EditItemTemplate>
on update event
DropDownList dropDept = (DropDownList)row.FindControl("dropDownDept");

Thank you


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

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

Login to post response