Question

Just to check, is the below codes correct? SubmitAppraisalGrid.DataBind()? It is because my second page was empty when I tried to view them. Or could it because I am binding a gridview inside a gridview? Please tell me if I need to update my code on binding my "inside" grid.

My code:

protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
    SubmitAppraisalGrid.DataBind();
}

Design:

<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>
Was it helpful?

Solution

Check your markup, you are not using any typed data source. if you are handling datagrid's databind event then put it in the code else add data source on PageIndexChanging event also..

protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
            SubmitAppraisalGrid.DataSource = (SomeDataSource that you are using);
            SubmitAppraisalGrid.DataBind();
        }

Refer GridView.PageIndexChanging Event.

OTHER TIPS

I solved it this way:

Inside Gridview index 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();
}

Use same Query which using in Databind

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top