Connecting Tech Pros Worldwide Help | Site Map

dropdownlist in datagrid

Newbie
 
Join Date: Sep 2009
Posts: 4
#1: Sep 18 '09
i had a dropdownlist in datagrid. datagrid showing details of a table.
i want dropdownlist list items from other table. where one column in both tables is same. and droplist should update whenever i update the data grid.
code i tried....

<asp:DropDownList ID="DropDownList1" AutoPostBack="true" DataTextField="dept" DataValueField="dept" runat="server" DataSource="<%# ddllist()%>">
</asp:DropDownList>


protected void DataGid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
SqlConnection cnn = new SqlConnection("Data Source=NETZOOM\\MADHUK_2005;Integrated Security=SSPI;Initial Catalog=master");

string sql = "select dept from dptmnt";
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(sql, cnn);
cmd.Connection.Open();
SqlDataAdapter ad1 = new SqlDataAdapter(cmd);
ad1.Fill(ds, "dptmnt");


if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList DropDownList1 = (DropDownList)((DataGridItem)e.Item).FindControl(" DropDownList1");
ListItem li = new ListItem();
DropDownList1.Items.Add(li);
DropDownList1.DataSource = ds.Tables["dptmnt"].DefaultView;
DropDownList1.DataValueField = "dept";
DropDownList1.DataTextField = "dept";
DropDownList1.DataBind();
cmd.Connection.Close();


}
}
public DataSet ddllist()
{
string sql = "select dept from dptmnt";
SqlDataAdapter ad1 = new SqlDataAdapter(sql, cnn);
DataSet ds = new DataSet();
ad1.Fill(ds, "dptmnt");
return ds;
}
thanks...
Madhu.k
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,751
#2: Sep 18 '09

re: dropdownlist in datagrid


SInce there is no question in there... and you sound like you are expecting someone to write it for you... Are you asking for bids of what it would cost?
Reply