Details View and Drop Down List
I have a details view and in the details view I have two template fields together with other fields. Those template fields are dropdown lists. The first dropdown list displays Departments and the second one displays Products. Both of them are populated from the database. I want to display only those products in the Products (second dropdown list) which belong to the department (first dropdown list) which is selected by the user. I am trying to set the select parameter, but details view does not allow me to do it. Can you please help me?
Nipun TomarPosted Jul 29, 2008, 12:17 PM
{
try {
DropDownList ddlState = (DropDownList)sender;
ListItem listItem = new ListItem("--Select--", "");
ddlState.Items.Insert(0, listItem);
Data.DataRowView View = DetailsViewPrimary.DataItem;
ddlState.SelectedValue = View.Item("StateProvinceID").ToString();
ObjectDataSourceCounty.FilterExpression = "StateProvinceID='" + ddlState.SelectedValue + "'";
}
catch (Exception ex) {
}
try {
DropDownList ddlState = (DropDownList)sender;
Data.DataRowView View = DetailsViewMailing.DataItem;
ddlState.SelectedValue = View.Item("StateProvinceID").ToString();
ObjectDataSourceCounty.FilterExpression = "StateProvinceID='" + ddlState.SelectedValue + "'";
}
catch (Exception ex) {
}
}
Nipun TomarPosted Jul 28, 2008, 4:19 PM
<
asp:TemplateField HeaderText="State:"><EditItemTemplate>
<asp:DropDownList ID="DropDownListState" runat="server" DataSourceID="ObjectDataSourceState" DataTextField="StateProvince" DataValueField="StateProvinceID" OnDataBound="DropDownListState_DataBound" OnSelectedIndexChanged="DropDownListState_SelectedIndexChanged" AutoPostBack="true">
asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="DropDownListState" runat='server' ID="RequiredFieldValidatorTextBoxState" ErrorMessage="*">asp:RequiredFieldValidator>
EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownListState" runat="server" DataSourceID="ObjectDataSourceState" DataTextField="StateProvince" DataValueField="StateProvinceID" OnDataBound="DropDownListState_DataBound" OnSelectedIndexChanged="DropDownListState_SelectedIndexChanged" AutoPostBack="true">
asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="DropDownListState" runat='server' ID="RequiredFieldValidatorTextBoxState" ErrorMessage="*">asp:RequiredFieldValidator>
InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("StateProvince") %>'>asp:Label>
ItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="County:">
<EditItemTemplate>
<asp:DropDownList ID="DropDownListCounty" runat="server" DataSourceID="ObjectDataSourceCounty" DataTextField="County" DataValueField="CountyID" OnDataBound="DropDownListCounty_DataBound">
asp:DropDownList>
EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownListCounty" runat="server" DataSourceID="ObjectDataSourceCounty" DataTextField="County" DataValueField="CountyID" OnDataBound="DropDownListCounty_DataBound">
asp:DropDownList>
InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("County") %>'>asp:Label>
ItemTemplate>
asp:TemplateField>
Protected
Sub DropDownListState_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)Try
Dim ddlState As DropDownList = CType(sender, DropDownList)
Dim listItem As ListItem = New ListItem("--Select--", "")
ddlState.Items.Insert(0, listItem)
Dim View As Data.DataRowView = DetailsViewPrimary.DataItem
ddlState.SelectedValue = View.Item("StateProvinceID").ToString()ObjectDataSourceCounty.FilterExpression = "StateProvinceID='" + ddlState.SelectedValue + "'"
Catch ex As Exception
End Try
Try
Dim ddlState As DropDownList = CType(sender, DropDownList)
Dim View As Data.DataRowView = DetailsViewMailing.DataItem
ddlState.SelectedValue = View.Item("StateProvinceID").ToString()ObjectDataSourceCounty.FilterExpression = "StateProvinceID='" + ddlState.SelectedValue + "'"
Catch ex As Exception
End Try
End Sub
r pPosted Aug 1, 2008, 10:37 AM
I am still getting error like this-
Error 1 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The name 'DetailsViewPrimary' does not exist in the current context
Error 4 The name 'DetailsViewMailing' does not exist in the current context
Thanks
r pPosted Jul 29, 2008, 11:40 AM
Thanks