Click here to Skip to main content
15,896,040 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i apply dropdown list inside the listview they add only null value why?

Currently I have a dropdownlist with it's own sqldatasource that's populating the dropdownlist. The ddl is inside a listviews, which also has it's on sqldatasource, insert item template. However when we click insert the value passed to the dbase is a null.

When i apply single dropdown list using below code they work fine, But when i apply 2 dropdown list, second dropdown inherited with first dropdown they cannot work, They passing out null value.

First dropdown is "nationality" and second dropdown is a "province",
When i select nationality, than province will be automatically show from database, but when we aplly those dropdown inside listview than they add only null value.

But if i add only nationality dropdown, they successfully add data to the db

What I have tried:

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="AreaId" InsertItemPosition="LastItem">
<insertitemtemplate>
<asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" CssClass="btn-warning" Width="50px" Height="25px" />
<asp:Button runat="server" CommandName="Cancel" Text="Clear" ID="CancelButton" CssClass="btn-warning" Width="50px" Height="25px" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<progresstemplate>
<img alt="as" src="Images/loader1.gif" style="width: 30px; height: 30px" />


<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("ProvinceId") %>' CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" DataSourceID="SqlDataSource4" DataTextField="ProvinceName" DataValueField="ProvinceId">
<asp:SqlDataSource runat="server" ID="SqlDataSource4" ConnectionString='<%$ ConnectionStrings:CRMSConnectionString %>' SelectCommand="SELECT * FROM [Province]">
<asp:DropDownList ID="DropDownList4" runat="server" SelectedValue='<%# Bind("CityId") %>' CssClass="form-control" DataSourceID="SqlDataSource5" DataTextField="CityName" DataValueField="CityId">
<asp:SqlDataSource runat="server" ID="SqlDataSource5" ConnectionString='<%$ ConnectionStrings:CRMSConnectionString %>' SelectCommand="SELECT City.CityId, City.CityName FROM City INNER JOIN Province ON City.ProvinceId = Province.ProvinceId WHERE (City.ProvinceId = @ProvinceId)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="ProvinceId">
</SelectParameters>

<asp:TextBox Text='<%# Bind("AreaName") %>' runat="server" ID="AreaNameTextBox" CssClass="form-control" />


<asp:SqlDataSource runat="server" ID="SqlDataSource3" ConnectionString='<%$ ConnectionStrings:CRMSConnectionString %>' DeleteCommand="DELETE FROM [Area] WHERE [AreaId] = @AreaId" InsertCommand="INSERT INTO [Area] ([AreaName], [CityId], [ProvienceId]) VALUES (@AreaName, @CityId, @ProvienceId)" SelectCommand="SELECT * FROM [Area]" UpdateCommand="UPDATE [Area] SET [AreaName] = @AreaName, [CityId] = @CityId, [ProvienceId] = @ProvienceId WHERE [AreaId] = @AreaId">
<deleteparameters>
<asp:Parameter Name="AreaId" Type="Int32">

<insertparameters>
<asp:Parameter Name="AreaName" Type="String">
<asp:Parameter Name="CityId" Type="Int32">
<asp:Parameter Name="ProvienceId" Type="Int32">

<updateparameters>
<asp:Parameter Name="AreaName" Type="String">
<asp:Parameter Name="CityId" Type="Int32">
<asp:Parameter Name="ProvienceId" Type="Int32">
<asp:Parameter Name="AreaId" Type="Int32">
Posted
Comments
Vincent Maverick Durano 23-Jun-16 14:13pm    
But where is you Nationality DropDown? I can't seem to find it. Also it's not included in your parameters.
Member 11041681 24-Jun-16 5:42am    
dropdown1=Province and dropdown4=City when i click "province", "City" will be automatically show from database(which is inherited with "Province"). But when i click add button they passing out null values into db. Why?
How I resolve?
Member 11041681 24-Jun-16 1:42am    
dropdown1=Province and dropdown4=City when i click "province", "City" will be automatically show from database(which is inherited with "Province"). But when i click add button they passing out null values into db. Why?
How I resolve?
Vincent Maverick Durano 24-Jun-16 9:08am    
Where are your insert parameters? you should define each fields that needs to be inserted to your DB.
Member 11041681 24-Jun-16 12:03pm    
Insert Button:
<asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" CssClass="btn-warning" Width="50px" Height="25px" />

Dropdownlist's:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("ProvinceId") %>' CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" DataSourceID="SqlDataSource4" DataTextField="ProvinceName" DataValueField="ProvinceId">
<asp:SqlDataSource runat="server" ID="SqlDataSource4" ConnectionString='<%$ ConnectionStrings:CRMSConnectionString %>' SelectCommand="SELECT * FROM [Province]">
<asp:DropDownList ID="DropDownList4" runat="server" SelectedValue='<%# Bind("CityId") %>' CssClass="form-control" DataSourceID="SqlDataSource5" DataTextField="CityName" DataValueField="CityId">
<asp:SqlDataSource runat="server" ID="SqlDataSource5" ConnectionString='<%$ ConnectionStrings:CRMSConnectionString %>' SelectCommand="SELECT City.CityId, City.CityName FROM City INNER JOIN Province ON City.ProvinceId = Province.ProvinceId WHERE (City.ProvinceId = @ProvinceId)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="ProvinceId">
</SelectParameters>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900