开发者

Populate textboxes from SQL Datasource Stored Procedure

I have a database that has data like first name, last name, address, etc. I would like to be able to use my stored procedure I created. Here is my stored procedure.

ALTER PROCEDURE Edituser
@uid int
AS
Select * From Contacts
Where UserID=@uid

Now on my page in Visual Studio I create a SQLDatasource, 开发者_JAVA技巧link it to that Stored Procedure, and then how do I populate text boxes with that data that it has retrieved? I am not sure if I should use like the reader and do a loop maybe, im not sure so hopefully someone can help.

Thank You


Try using a DetailsView or a FormView and bind the columns to the appropriate display controls.


The easiest way is to click on the control you want to data bind in design view, click the arrow to expand options, and select "Choose data source..." Your SqlDataSource should show up on there, just choose it and then the fields you want to display or use. (You may need to click "Refresh schema" at the bottom).

Alternatively, you can bind controls to data sources programatically:

    protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList1.DataSource = SqlDataSource1;
        DropDownList1.DataTextField = "foo";
        DropDownList1.DataValueField = "bar";
        DropDownList1.DataBind();
    }

Or, you can do the query manually like reggie shows if you need to manipulate or remove some data before binding it directly to a control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜