开发者

ASP Stored Procedure to GridView

开发者 https://www.devze.com 2023-01-03 21:32 出处:网络
I am attempting to use an existing stored procedure to populate a gridview. First, I execute the stored procedure and use a SqlAdapter to put it into a DataSet. I know this works because DataSet.Tabl

I am attempting to use an existing stored procedure to populate a gridview.

First, I execute the stored procedure and use a SqlAdapter to put it into a DataSet. I know this works because DataSet.Tables[0] contains my data. However, w开发者_开发技巧hen I create a GridView and bind the data to the GridView, nothing is displayed.

Here is the code for binding the GridView:

DataSet ds = Execute_spr();
GridView testGridView = new GridView();

if (ds.Tables.Count > 0)
{
   testGridView.DataSource = ds.Tables[0].AsEnumerable();
   testGridView.DataBind();
}

and here is the code for my gridview in the .aspx page:

<asp:GridView ID="testGridView" runat = "server" AutoGenerateColumns = "true" />

Any idea what I might be doing incorrectly?

Edit: I have tried the ds.Tables[0] without AsEnumerable() and using .DefaultView


Why are you re-initialising the Gridview in the line

GridView testGridView = new GridView();

Create a protected member in your codebeind called "testGridView", remove the line above, and you might start to get somewhere...

0

精彩评论

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