我有一个Gridview
和Object data source
,并使用Object data source
来绑定Gridview
,如下所示:
<asp:GridView ID="grdProducts" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
GridLines="None" AllowPaging="true" PageSize="10" DataSourceID="ObjDataSource">
<Columns>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjDataSource" runat="server"
SelectCountMethod="Count" SelectMethod="Get"
TypeName="App.Data.Products" EnablePaging="true"
StartRowIndexParameterName="skip"
MaximumRowsParameterName="take">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="id" Name="ID" ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:ObjectDataSource>
我有一个按钮,并在OnClick
事件上写下了代码:
foreach (GridViewRow row in grdProducts.Rows)
{
Response.Write("A<br />");
}
当我跑步时,我会在Gridview
中看到超过1行,但是当我点击按钮时,A
只写了一次!
当我写grdProducts.Rows.Count
时,我得到了1。
错误的部分是什么?
谢谢!
答案 0 :(得分:0)
将代码更改为:
string textToPrint = string.empty;
foreach (GridViewRow row in grdProducts.Rows)
{
textToPrint += "A<br />";
}
Response.Write(textToPrint);