这里是cs:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Book_id" EnablePersistedSelection="True" BackColor="White" Height="240px"
Width="755px" BorderColor="Red" BorderWidth="2px">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
ReadOnly="True" SortExpression="Book_id" >
<ControlStyle BorderColor="Red" />
</asp:BoundField>
<asp:BoundField DataField="bookid" HeaderText="bookid" SortExpression="bookid" />
<asp:BoundField DataField="studentid" HeaderText="studentid" SortExpression="studentid" />
<asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
<asp:BoundField DataField="returndate" HeaderText="returndate" SortExpression="returndate" />
<asp:BoundField DataField="returnstatus" HeaderText="returnstatus" SortExpression="returnstatus" />
</Columns>
</asp:GridView>
ASPX:
{{1}}
以下是我执行的查询的screenshot
我是.net的新手,任何人都可以通过调用storedprocedure来指导我在gridview中显示数据。
谢谢,
答案 0 :(得分:3)
试试这个
SqlConnection con = Connection.DBconnection();
SqlCommand com = new SqlCommand("sp_logdetails", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@bookid",1);
SqlDataAdapter adp = new SqlDataAdapter(com);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
您需要将@bookid
参数传递给SP。我已将@bookid
的值硬编码为1,但您需要将其作为parameter
传递。