views:

231

answers:

1

I have created database which has columns

 - MemName
 - monthlyAmt
 - CurrentInstAmt

I have bound the Memname column with a DropDownList box;
onselection of memname value in DropDownList box, the corresponding values of currentInstAmt and monthlyamt should be displayed in Textbox.

I am beginer in asp.net

code -

DataSet dsMemname = new DataSet();
        try
        {
            con.ConnectionString = strcon;
            con.Open();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_Memcollection";
            SqlDataAdapter adp = new SqlDataAdapter(cmd.CommandText, con);
            adp.Fill(dsMemname);
            ddlmemname.DataTextField = "MemName";
            ddlmemname.DataSource = dsMemname;
            ddlmemname.DataBind();
        }
        catch (Exception ex)
        {

            throw ex;
        }
+1  A: 

EDIT: First, set your dropdownlist's DataValueField, just like the DataTextField: as so:

ddlmemname.DataValueField = "MemName";

END EDIT

Set your dropdownlist's autopostback="True" as so:

<asp:dropdownlist id="DropDownList1" runat="server" autopostback="true">
</asp:dropdownlist>

and then in the code behind for your page, add an event for your drop down as so:

Protected Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
    Dim selval As String = DropDownList1.SelectedValue

    TextBox1.Text = getMonthlyAmt(selval)
    TextBox2.Text = getCurrentAmt(selval)
End Sub

The two get() methods are your own code to look up your relevant values. Also, you may want to optimize them to one call in some manner depending on where you're pulling them from and performance considerations.

eidylon
Thanks, but dnt get properly
I'm not sure what your comment means, so I'm not sure what didn't work or what you need expounded upon. Do you mean you didn't get a SelectedValue? This may be because you did not set the DataValueField in your code. It needs to be set, just like DataTextField.
eidylon