locked
Dropdownlist+SqlDataSource+ControlParameter+SelectedIndexChange RRS feed

  • Question

  • User690405973 posted

    I got two dropdownlist(ddMain1,ddSub1)

    I got two sqldatasource(SQLDataSource1,SQLDataSource2)

    I got one button(btnEdit)

    ddMain1 bind data to SQLDataSource1

    ddSub1 bind data to SQLDataSource2 with control parameter value from ddMain1

    in btnEdit_Click event i want to change selected value of (ddMain1 , ddSub1)

    but the process flow is like this:

    Page_Load > btnEdit_Click

    so the selectedindexchange event not trigger to control(ddMain1 , ddSub1) and selectedvalue cannot been given value to ddSub1 as long as btnEdit_Click event did not finish

    so I want to make the process flow become this:

    Page_Load > btnEdit_Click > ddMain1_SelectedIndexChanged > ddSub1_SelectedIndexChanged

    __________________________________________________________________________________________________________

    <table runat="server" id="Table2" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td valign="top"><table border="0" cellpadding="1" cellspacing="5"><tbody><tr>
                    <td><label>Main Case</label></td>
                    <td>
                        <label>:</label>
                        <asp:label id="lblMain1" runat="server" text="" font-bold="True" font-names="Agency FB"></asp:label>
                        </td>
                    <td colspan="2"><asp:dropdownlist cssclass="Right" id="ddMain1" datasourceid="SqlDataSource1" datavaluefield="DetailID" datatextfield="DetailDesc" runat="server" autopostback="True">
                        </asp:dropdownlist></td>                    
                </tr><tr>
                    <td><label>Sub Case</label></td>
                    <td>
                        <label>:</label>
                        <asp:label id="lblSub1" runat="server" text="" font-bold="True" font-names="Agency FB"></asp:label></td>
                    <td colspan="2"><asp:dropdownlist cssclass="Right" id="ddSub1" datasourceid="SqlDataSource2" datavaluefield="DetailID" datatextfield="DetailDesc" runat="server" autopostback="True">
                        </asp:dropdownlist></td>
                    <td><label>IP Open Date</label></td>               
                </tr>
    </tbody></table>
    <asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="Data Source=10.1.2.68;Database=e-IRS;User ID=sa;Password=sa;" selectcommand="SELECT [DetailID],[DetailDesc] FROM [e-IRS].[dbo].[View_MainCase]"></asp:sqldatasource>
         <asp:sqldatasource id="SqlDataSource2" runat="server" connectionstring="Data Source=10.1.2.68;Database=e-IRS;User ID=sa;Password=sa;" selectcommand="SELECT '-1' AS [DetailID],'Choose Sub' AS [DetailDesc] UNION SELECT [DetailID],[DetailDesc] FROM [e-IRS].[dbo].[CaseDetail] WHERE [ParentID] = @DetailID">
            <selectparameters>
                <asp:controlparameter name="DetailID" controlid="ddMain1" propertyname="SelectedValue" type="Int32" defaultvalue="">
            </asp:controlparameter>
         </selectparameters>
    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
    ddMain1.SelectedValue = HidDMain.Value
    ddSub1.SelectedValue = HidDSub.Value
    End Sub
    Protected Sub ddMain1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddMain1.SelectedIndexChanged
            If ddMain1.SelectedValue &gt; 0 Then
                lblMain1.Text = HidMain1.Value &amp; "0" &amp; ddMain1.SelectedValue
            Else
                lblMain1.Text = ""
                lblSub1.Text = ""
            End If
        End Sub
        Protected Sub ddSub1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddSub1.SelectedIndexChanged
            If ddSub1.SelectedValue &gt; 0 Then
                lblSub1.Text = HidSub1.Value &amp; "-" &amp; ddSub1.SelectedValue
            Else
                lblSub1.Text = ""
            End If
        End Sub

    Wednesday, November 4, 2009 9:24 PM

Answers

  • User1269925535 posted

    hi...

    try to solve your problem in diffrent way....

    some thing like this:

    public partial class _Default : System.Web.UI.Page 
    {
        string Main1, Sub1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Main1 = ddMain1.SelectedValue;
                Sub1 = ddSub1.SelectedValue;
            }
            else
            {
                if (Main1 == ddMain1.SelectedValue && Sub1 == ddSub1.SelectedValue)
                {
                    //do what u want
                }
            }
            Main1 = ddMain1.SelectedValue;
            Sub1 = ddSub1.SelectedValue;
        }
     
    }
    


    ---------------

    dont forget to mark as answerd..........

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 5, 2009 12:27 AM