Search code examples
c#asp.netsql-servervb.netwindow

declare dropdown selected data asp.net vb


<td style="width: 10%;">
                    <asp:DropDownList runat="server" ID="ddlMonth" AutoPostBack="true">
                        <asp:ListItem>Month</asp:ListItem>
                        <asp:ListItem>January</asp:ListItem>
                        <asp:ListItem>February</asp:ListItem>
                        <asp:ListItem>March</asp:ListItem>
                        <asp:ListItem>April</asp:ListItem>
                        <asp:ListItem>May</asp:ListItem>
                        <asp:ListItem>June</asp:ListItem>
                        <asp:ListItem>July</asp:ListItem>
                        <asp:ListItem>August</asp:ListItem>
                        <asp:ListItem>September</asp:ListItem>
                        <asp:ListItem>October</asp:ListItem>
                        <asp:ListItem>November</asp:ListItem>
                        <asp:ListItem>December</asp:ListItem>
                    </asp:DropDownList>
                </td>

Actually i want to make the dropdownlist selected item go to back vb page. How can i declare the selected item?

After that how to insert to the sql statement?

  lsCmd = "SELECT * FROM"
            lsCmd &= " (SELECT DISTINCT code, upload, DATEPART(dd, [date]) as Date"
            lsCmd &= " FROM edrsDB..tbl_users"
            lsCmd &= " left join edrsDB..edrs_upload"
            lsCmd &= " ON edrs_upload.userid = tbl_users.userID"
            lsCmd &= " WHERE DATEPART(MM, [date])= " & SQLQUOTE(Trim(ddlMonth.SelectedIndex))
            lsCmd &= " And DATEPART(YYYY, [date])= " & SQLQUOTE(Trim(ddlYear.SelectedIndex))
            lsCmd &= " And date IS NOT NULL) AS monthlyRpt"
            lsCmd &= " PIVOT (MAX(upload)"

Solution

  • You can do it in code behind:

    DropDownList1.SelectedItem.Text = "January"
    

    or

    //selecting by index

    DropDownList1.SelectedIndex = 5;