Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm returning a set of values like ID and Name from a procedure and displaying it in an element in an interface using ajax.

SQL
ALTER procedure [dbo].[ap1]
@id int
as
begin
select id,name from sb where id=@id
end


I'm displayin the ID and Name in a textbox in the form using ajax.
Can I display ID and Name separately in different elements, like ID in textbox1 and Name in textbox2 using ajax?
Posted
Updated 8-Sep-10 21:46pm
v2
Comments
Dalek Dave 9-Sep-10 3:47am    
Edited for Grammar and Readability.

1 solution

I assume that you are using ASP.NET inbuilt ajax support and you want to display the information on a button click event.

The following is a code sample for Button Click Event.
protected void btnShowData_Click(object sender, EventArgs e)
{
    //Fill the DataTable
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = connection; //specify connection object here
    cmd.CommandText = "ap1";    //Name of stored procedure
    cmd.CommandType = CommandType.StoredProcedure;

    #region Parameters
    //Add the parameter id required for the SP
    SqlParameter p = new SqlParameter();
    p.ParameterName = "@id";
    p.Value = "1"; // Specify parameter value
    p.SqlDbType = SqlDbType.Int;
    cmd.Parameters.Add(p);
    #endregion
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        txtID.Text = dt.Rows[0]["id"];
        txtName.Text = dt.Rows[0]["name"];
    }
}


Make sure that you are placing the two text boxes and a button in an update panel.
 
Share this answer
 
v3
Comments
Dalek Dave 9-Sep-10 3:47am    
Good Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900