how to bind data in dropdown inside gridview in asp.net [Resolved]

Posted by Gow.Net under ASP.NET on 10/19/2012 | Points: 10 | Views : 18600 | Status : [Member] | Replies : 3
how to bind data in dropdown inside gridview in asp.net?

gowthaman8870226416


Responses

Posted by: Gow.Net on: 10/19/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
thanks for your replay
i also got solution

<asp:DropDownList ID="ddl_groub" runat="server" DataSource='<%# group_collection %>' >

</asp:DropDownList>


public void bindgroub()

{

code = Session["UseCode"].ToString();
g.U_code = code;
list = new List<Groupbo>();
group_collection=new List<string>();
list = new GroupBAL().group_bind(g);

foreach (Groupbo gg in list)
{
group_collection.Add(gg.Groupname);
}

}


gowthaman8870226416

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

Posted by: Lalitha86 on: 10/19/2012 [Member] Starter | Points: 25

Up
0
Down


<asp:GridView ID="gvUserInfo" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvUserInfo_RowDataBound" >
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
<Columns>
<asp:BoundField DataField="CountryId" HeaderText="CountryId" />
<asp:BoundField DataField="CountryName" HeaderText="CountryName" />
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:DropDownList ID="ddlCity" runat="server" Width="100px"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>








ddl.DataSource = ds;
ddl.DataTextField = "StateName";
ddl.DataValueField = "StateID";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("--Select--", "0"));

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

Posted by: Lalitha86 on: 10/19/2012 [Member] Starter | Points: 25

Up
0
Down
protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
var ddl = (DropDownList)e.Row.FindControl("ddlCity");
int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
SqlCommand cmd = new SqlCommand("select * from State where CountryID=" + CountryId, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl.DataSource = ds;
ddl.DataTextField = "StateName";
ddl.DataValueField = "StateID";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("--Select--", "0"));
}




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

Login to post response