471,075 Members | 771 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

dropdownlist in datagrid

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()%>">

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);
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.DataSource = ds.Tables["dptmnt"].DefaultView;
DropDownList1.DataValueField = "dept";
DropDownList1.DataTextField = "dept";

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;
Sep 18 '09 #1
1 1968
3,525 Expert 2GB
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?
Sep 18 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Shiju Poyilil | last post: by
1 post views Thread by m3ckon | last post: by
3 posts views Thread by Tim::.. | last post: by
reply views Thread by Daniel Doyle | last post: by
4 posts views Thread by Mark Waser | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.