SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to paging in gridview.

    using c# asp.net 2.0

    i want to do paging in gridview....i want to display 3 records in one page....
    i did allow paging property to true..and also did page size = 3 and also did pagersetting position= top...
    then also if i m clicking on page2 the next data is not displaying.. y this prob is coming?

    m sending u the source code of gridview please check whether its correct..if not then please update it...

    <tr>
    <td>
    <asp:GridView ID="gvDepartment" runat="server" CssClass="GridRowFormat" AutoGenerateColumns="False" Width=60%
    UseAccessibleHeader="False" OnSelectedIndexChanged="gvDepartment_SelectedIndexChanged" AutoGenerateEditButton="True" OnRowEditing="EditRecords" OnRowUpdating="UpdateRecords" OnRowCancelingEdit="CancelRecords" OnRowDataBound="gvDepartment_RowDataBound" AllowPaging="True" OnPageIndexChanged="gvDepartment_PageIndexChanged" OnPageIndexChanging="gvDepartment_PageIndexChanging" PageSize="3" >
    <HeaderStyle CssClass="DataGridFixedHeader" />
    <Columns>
    <asp:BoundField HeaderText="DEPARTMENT_ID" Visible="False" />

    <asp:TemplateField HeaderText="Department Name">
    <ItemTemplate>
    <%# Eval("DEPARTMENT_NAME") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtDeptname" runat="Server" Text='<%# Eval("DEPARTMENT_NAME") %>'>
    </asp:TextBox>
    <asp:TextBox ID="txtDeptnameOld" runat="Server" Text='<%# Eval("DEPARTMENT_id") %>' Visible="false">
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Status">
    <ItemTemplate>
    <%# Eval("Status") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:RadioButtonList ID="rdlstStatus" runat=server RepeatDirection=Horizontal>
    <asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
    <asp:ListItem Text="No" Value="N"></asp:ListItem>
    </asp:RadioButtonList>
    </EditItemTemplate>
    </asp:TemplateField>
    </Columns>
    <AlternatingRowStyle CssClass="GridRowAlternative" />
    <PagerSettings Position="Top" />
    </asp:GridView>
    </td>
    </tr>

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,875
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did paging...and also its working...by writing this code on this event.

    protected void gvTechnician_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
    gvTechnician.PageIndex = e.NewPageIndex;
    gvTechnician.DataBind();
    LoadTechnican();
    }

    but now some forms are working fine....but in some forms having large no. of columns there m getting this error..

    specified argument was out of the range of valid values..Parameter name:index.....

    can anyone help me to solve this prob?

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i understand where m getting error.
    m getting error in gridview row data bound...
    but this error only comes when m doing paging..otherwise its working.

    i think i have to add something on this code to do paging. it must be syntax error. do anyone know how to solve this?

    protected void gvExistingIncident_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType.ToString() != "Header" && e.Row.RowType.ToString() != "Footer")
    {
    string id = "";
    id = ((LinkButton)e.Row.Cells[1].FindControl("lnkbtnTicketId")).Text;
    ((LinkButton)e.Row.Cells[1].FindControl("lnkbtnTicketId")).PostBackUrl = "ExistingIncidentDetail.aspx?ID=" + id;
    }
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •