只是为了检查,以下代码是否正确? SubmitAppraisalGrid.DataBind()
?这是因为当我试图查看它们时,我的第二页是空的。或者是因为我在gridview中绑定了gridview?请告诉我是否需要在绑定“内部”网格时更新我的代码。
我的代码:
protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
SubmitAppraisalGrid.DataBind();
}
设计
<asp:GridView ID="SubmitAppraisalGrid" runat="server" AutoGenerateColumns="False" BorderWidth="0px" onrowcreated="SubmitAppraisalGrid_RowCreated" ShowHeader="False" style="margin-right: 0px" AllowPaging="True" PageSize="1" OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="QuestionLbl" runat="server" Text='<%# Bind("Question")%>'></asp:Label>
<br />
<br />
<asp:GridView ID="StaffAppraisalGrid" runat="server"AutoGenerateColumns="False" BorderWidth="0px" CellPadding="4" CellSpacing="2">
<Columns>
<asp:BoundField DataField="StaffName" HeaderText="Name">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:RadioButtonList ID="RadioList" runat="server" CellPadding="8"
DataSource='<%# Bind("RadioButtonList")%>' RepeatDirection="Horizontal">
</asp:RadioButtonList>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:TextBox ID="RemarksTbx" runat="server" CssClass="remarkTbx"
MaxLength="500" Text='<%# Bind("RemarkTbx")%>' TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
答案 0 :(得分:0)
检查您的标记,您没有使用任何类型化的数据源。如果你正在处理datagrid的databind事件,那么把它放在代码中,或者在PageIndexChanging
事件上添加数据源..
protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
SubmitAppraisalGrid.DataSource = (SomeDataSource that you are using);
SubmitAppraisalGrid.DataBind();
}
答案 1 :(得分:0)
我这样解决了:
内部Gridview索引Canging
{
GridView1.PageIndex = e.NewPageIndex;
SqlCommand cmd = new SqlCommand("Select * from Emp_Data ORDER BY [ID] DESC", con);
SqlDataAdapter DA1 = new SqlDataAdapter(cmd);
DA1.Fill(DT1);
GridView1.DataSource = DT1;
GridView1.DataBind();
}
使用在Databind中使用的相同查询