how do i fill my textbox based on the selection in dropdownlist using sql procedure RRS feed

  • Question

  • User-1849856862 posted

    Hi, how do i fill my textbox based on the selection in drop downlist using sql procedure.

    i select Name in the dropdownlist 

    i wish to have contact number and department display in my textbox.

    Thursday, April 26, 2018 3:28 AM

All replies

  • User61956409 posted


    The OnSelectedIndexChanged event of DropDownList control will fire when the selected index has been changed, in this event you can call your Stored Procedures using ADO.Net to retrieve contact number and department information from your database and assign the value to textbox.

    You can refer to this article: “Calling Select SQL Server Stored Procedures using ADO.Net” to call your Stored Procedures.

    With Regards,

    Fei Han

    Friday, April 27, 2018 2:28 AM
  • User-1716253493 posted

    It's similar when using sql command with commandtype.text

    You need a parameter in stored procedure, then modify your code

    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "mysp";
    cmd.Parameters.AddWithValue("@param1", ddl.SelectedValue);
    CREATE PROCEDURE mysp(@Param1 varchar)
    	select * from Users where userName=@Param1

    Friday, April 27, 2018 2:41 AM