Hello, I am new to this - please be gentle... Is it possible (and if so how) to have a dropdown within a gridview? Specifically, I would like to have data from Table B in the dropdown within the datagrid that has Table A data... You help is greatly appreciated!
I have this working now - drop down reads values from Table B... I'm having trouble getting the selected value stored in the corresponding field of Table A. For instance - Table A (GridView table) field "EventType" (number field) is linked to Table B (dropdown
source) field "EventTypeID". Somehow, I need to figure out how to use the value from Table B and have that updated in to Table A. Any help would be great!! Thank You
you can use something like the following GridViewRow row = GridView1.Rows[e.RowIndex]; Control c = row.FindControl("DropDownList1"); (c as DropDownList).SelectedValue will get you the value
If you use the a data source controls you can use the Bind expression for the DropDownLists SelectedValue instead of Eval, make sure you have added a parameter for the update command in the SqlDataSource that will get the data from table A. Take a look at this
example:
When you press the edit button next to the row, the dropdown list for contact title will appear. If you change the value of the dropdown and press the update button, the value will be saved. The example above uses the Northwind database it you
want to test it. If you want to get the value from a control programmatically when you do an update,
”>you can take a look at this post for an example
How come when I try to copy this code into my webform, that I get a lot of errors? Like "The active schema does not support the element 'asp:GridView'" ?
I have a related question: I've got one drop down list working fine, but how would I go about getting two linked drop down lists working? That is, I've got country and province information in a database. I want the users to be able to choose a country from
the first dropdown list (ddCountry), and that value is passed to the second drop down list (ddProvince). ddProvince should be populated from the country parameter passed from ddCountry. I can do this no problem in a regular page, but when I try to do it in
a Gridview, it gives me an error, saying that the ddProvince control doesn't support being bound. If anyone has any idea how to get this working, I'd appreciate it. Here's a code snippet:
<asp:DropDownList
ID="ddCountry"
Runat="server"
DataSourceID="SqlDataSource1"
DataTextField="Country"
DataValueField="Country_ID"
SelectedValue=''
AutoPostBack="True">
<asp:SqlDataSource
ID="SqlDataSource1"
Runat="server"
ConnectionString=""
SelectCommand="select Country_ID, Country from Country" >
<asp:DropDownList
ID="ddProvince"
Runat="server"
DataSourceID="SqlDataSource2"
DataTextField="Province"
DataValueField="Province_ID"
SelectedValue='' >
<asp:SqlDataSource
ID="SqlDataSource2"
Runat="server"
SelectCommand="select Province_ID, Province from Province WHERE Province_C_ID = @Country_ID"
ConnectionString="">
urinalpuck
Member
70 Points
14 Posts
Dropdown within gridview??
Sep 02, 2004 02:16 AM|LINK
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dropdown within gridview??
Sep 02, 2004 04:05 AM|LINK
<asp:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False"> <asp:DropDownList ID="DropDownList1" Runat="server" DataSourceID="SqlDataSource2" DataTextField="ContactTitle" DataValueField="ContactTitle" SelectedValue=''> <asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]" ConnectionString=""> <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]" ConnectionString="">MVP, ASPInsider, WCF RIA Services Insider
My Blog
urinalpuck
Member
70 Points
14 Posts
Re: Dropdown within gridview??
Sep 02, 2004 12:47 PM|LINK
urinalpuck
Member
70 Points
14 Posts
Re: Dropdown within gridview??
Sep 02, 2004 08:35 PM|LINK
leelaram
Member
645 Points
129 Posts
Re: Dropdown within gridview??
Sep 03, 2004 01:29 AM|LINK
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dropdown within gridview??
Sep 03, 2004 04:40 AM|LINK
<asp:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False"> <asp:DropDownList ID="DropDownList1" Runat="server" DataSourceID="SqlDataSource2" DataTextField="ContactTitle" DataValueField="ContactTitle" SelectedValue=''> <asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]" ConnectionString=""> <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]" ConnectionString="" UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactTitle] = @ContactTitle WHERE [CustomerID] = @original_CustomerID">When you press the edit button next to the row, the dropdown list for contact title will appear. If you change the value of the dropdown and press the update button, the value will be saved. The example above uses the Northwind database it you want to test it. If you want to get the value from a control programmatically when you do an update, ”>you can take a look at this post for an exampleMVP, ASPInsider, WCF RIA Services Insider
My Blog
bjorngb
Member
70 Points
14 Posts
Re: Dropdown within gridview??
Dec 13, 2004 07:24 AM|LINK
Elegabalus
Member
315 Points
63 Posts
Re: Dropdown within gridview??
Dec 15, 2004 11:56 PM|LINK
<asp:DropDownList ID="ddCountry" Runat="server" DataSourceID="SqlDataSource1" DataTextField="Country" DataValueField="Country_ID" SelectedValue='' AutoPostBack="True"> <asp:SqlDataSource ID="SqlDataSource1" Runat="server" ConnectionString="" SelectCommand="select Country_ID, Country from Country" > <asp:DropDownList ID="ddProvince" Runat="server" DataSourceID="SqlDataSource2" DataTextField="Province" DataValueField="Province_ID" SelectedValue='' > <asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="select Province_ID, Province from Province WHERE Province_C_ID = @Country_ID" ConnectionString="">