c# populate dropdownlist based on dropdownlist in gridview

Apr 5 2016 10:35 PM
I have a gridview with it's own sqlDataSource. In the footer row, I have an Insert field to create a new row. However, that footer row is quite complex and I'm trying to figure out how to make it work.
What I would like to see happen, is that a user Selects the OTypeName ddl. Based on that selection, the OSpecies ddl is enabled and populates values based on the OTypeName ddl. The same can be said in relation to OSpecies and OVariety.
The user then inputs their own information into OAge, OYields, OPlantDate, and OPlantFrom.
The rest of the fields in the footer row are labels that will be populated based on the final OVariety selection.
The Insert button then adds all these columns to the gridview. 
I only need help with populating one ddl based on the ddl selection of another and how to populate a label based on a ddl selection.
 
Here's my code in the aspx file:
 
</asp:TemplateField>
<asp:TemplateField HeaderText="OTypeName" SortExpression="OTypeName">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server"
AutoPostBack="True"
DataSourceID="dsTypeName"
DataTextField="OrchardTypeName"
DataValueField="OrchardTypeID" >
</asp:DropDownList>
<asp:SqlDataSource ID="dsTypeName" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT * FROM [tblOrchardType]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("OTypeName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlTypeName"
runat="server"
AutoPostBack="True"
DataSourceID="dsTypeName"
DataTextField="OrchardTypeName"
DataValueField="OrchardTypeID"
>
</asp:DropDownList>
<asp:SqlDataSource ID="dsTypeName" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT * FROM [tblOrchardType]"></asp:SqlDataSource>
</FooterTemplate>
 
 
I'm not sure what to put in the aspx.cs file but here's what I have so far concerning the Index Change for the ddl:
public void ddlTypeName_SelectedIndexChanged(object sender, EventArgs e)
{
//Enable ddlSpecies
//Populate ddlSpecies based on ddlTypeName selection
var ddlTypeValue = ddlTypeName.SelectedValue;
}

Any help would be much appreciated!  
 
 

Answers (4)