Hi,
I have two tables, Item group and Items, where in I need to publish the drop downs in such a way that all the group names should be listed in first drop down and items should be listed in second dropdown according to the selected value in first drop down.
I know using cascading dropdown of ajax would be the easy method and I tried it but I am unable to understand few terms they have mentioned in example.
So tried with regular drop down.
I am using datasource for first drop down and populating it .
My problem is I am getting the required result in first dropdown but in second dropdown I am getting duplicate values
please let me know where I am going wrong
<td valign="top" width="100">
</td>
<td align="right" valign="middle" width="200">
<asp:Label ID="lblgroup" runat="server" Font-Bold="True"
Font-Names="Palatino Linotype" Font-Size="Small" Text="Item Group :"></asp:Label>
</td>
<td align="left" height="30" valign="middle" width="200">
<asp:DropDownList ID="ddlgroup" runat="server" DataSourceID="SqlDataSource1"
Font-Bold="False" Font-Names="Palatino Linotype" Font-Size="Small"
Width="150px" AutoPostBack="True" DataTextField="ITEMGROUPNAME"
DataValueField="ITEMGROUPNAME">
</asp:DropDownList>
</td>
<td width="250">
</td>
</tr>
<tr>
<td valign="top" width="100">
</td>
<td align="right" valign="middle" width="200">
<asp:Label ID="lblitem" runat="server" Font-Bold="True"
Font-Names="Palatino Linotype" Font-Size="Small" Text="Item :"></asp:Label>
</td>
<td align="left" height="30" valign="middle" width="200">
<asp:DropDownList ID="ddlitems" runat="server" Font-Names="Palatino Linotype"
Font-Size="Small" AutoPostBack="True" Width="150px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:conitemstring %>"
SelectCommand="SELECT [ITEMGROUPNAME] FROM [ITEMGROUP]"></asp:SqlDataSource>
.vb page
This below method is for displaying the second drop down based on first drop downs selected values
Protected Sub ddlgroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlgroup.SelectedIndexChanged
ddlitems.Items.Clear()
sqlstr = "Select ITEMGROUPCODE FROM ITEMGROUP WHERE ITEMGROUPNAME='" + ddlgroup.SelectedValue.ToString + "'"
sqlrdr = SqlHelper.ExecuteReader(sqlconn, CommandType.Text, sqlstr)
sqlrdr.Read()
sqlstr = "SELECT ITEMMASTER.ITEMCODE,ITEMMASTER.ITEMGROUPCODE,ITEMMASTER.ITEMNAME FROM ITEMMASTER,ITEMGROUP WHERE ITEMMASTER.ITEMGROUPCODE='" + sqlrdr(0).ToString + "'"
sqlrdr.Close()
sqlrdr = SqlHelper.ExecuteReader(sqlconn, CommandType.Text, sqlstr)
While (sqlrdr.Read())
ddlitems.Items.Add(sqlrdr(2))
End While
sqlrdr.Close()
End Sub
The below method is to display existing columns with the same item name as that of selected in second gridview
Protected Sub ddlitems_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlitems.SelectedIndexChanged
gdvitems.Dispose()
sqlstr = "SELECT ITEMCODE FROM ITEMMASTER WHERE ITEMNAME='" + ddlitems.SelectedValue.ToString + "'"
sqlrdr = SqlHelper.ExecuteReader(sqlconn, CommandType.Text, sqlstr)
sqlrdr.Read()
itemid = sqlrdr(0)
sqlrdr.Close()
sqlstr = "SELECT * FROM Item_loyalty_points_master WHERE ITEMCODE='" + itemid.ToString + "'"
sqlcmd = New SqlCommand(sqlstr, sqlconn)
sqladap = New SqlDataAdapter(sqlcmd)
sqlcmd.ExecuteNonQuery()
sqladap.Fill(ds)
gdvitems.DataSource = ds
gdvitems.DataBind()
End Sub