|
 |
aspdotnet_website_programming thread: Populate dropdown from database in a datagrid when editing a row
Message #1 by "Valerie Andersen (MERRYMAN)" <vande@m...> on Mon, 22 Apr 2002 13:56:32 -0700
|
|
I am trying to populate a dropdown list box from a database query. The
dropdown is located in a datagrid. The dropdown is used when the user
edits a row in the datagrid - to give the user specific choices. I can
get the dropdown to work fine outside of the datagrid, but inside the
datagrid the object isn't seen. Does anyone know of any examples I
could look at or suggestions on how to make this work?
Thanks,
Valerie
Message #2 by vop@i... on Tue, 23 Apr 2002 09:29:24
|
|
Try this one:
Control cGameCategory = EditReview.Items[0].FindControl("GameCategory");
((DropDownList) cGameCategory).DataTextField = "txt_kategoria";
((DropDownList) cGameCategory).DataValueField = "id_kategoria";
string Sql = "SELECT * FROM categories ORDER BY txt_kategoria ASC";
SqlDataAdapter Adapter = new SqlDataAdapter(Sql, Spojenie);
DataSet Ds = new DataSet();
Adapter.Fill(Ds, "categories");
((DropDownList) cGameCategory).DataSource = Ds.Tables["categories"];
((DropDownList) cGameCategory).DataBind();
EditReview -> my DataGrid
GameCategory -> my DropDownList
Message #3 by "Valerie Andersen (MERRYMAN)" <vande@m...> on Tue, 23 Apr 2002 09:56:39 -0700
|
|
Thanks - I actually got the dropdown populated successfully using a
dataset and just setting the datasource value of the dropdown to that
dataset through aspx i.e.
<EditItemTemplate>
=09
<asp:dropdownlist
=09
runat=3D"server"
=09
id=3D"ddl_type"
=09
DataValueField=3D'type'
=09
DataTextField=3D'type'
=09
DataSource=3D'<%# dsType %>'>
=09
</asp:DropDownList>
</EditItemTemplate>
Now my problem is setting the selected value to match the value
displayed in the cell before the user clicked the edit button - I can't
seem to get at the dropdownlist to set any of it's values, I am assuming
because it is embedded in the datagrid. Does anyone have any examples
of doing this that have worked?
Thanks,
Valerie
-----Original Message-----
From: vop@i... [mailto:vop@i...]
Sent: Tuesday, April 23, 2002 2:29 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] Re: Populate dropdown from
database in a datagrid when editing a row
Try this one:
Control cGameCategory =3D
EditReview.Items[0].FindControl("GameCategory");
((DropDownList) cGameCategory).DataTextField =3D "txt_kategoria";
((DropDownList) cGameCategory).DataValueField =3D "id_kategoria";
string Sql =3D "SELECT * FROM categories ORDER BY txt_kategoria ASC";
SqlDataAdapter Adapter =3D new SqlDataAdapter(Sql, Spojenie);
DataSet Ds =3D new DataSet();
Adapter.Fill(Ds, "categories");
((DropDownList) cGameCategory).DataSource =3D Ds.Tables["categories"];
((DropDownList) cGameCategory).DataBind();
EditReview -> my DataGrid
GameCategory -> my DropDownList
|
|
 |