SitePoint Sponsor

User Tag List

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

    how to find total no. of rows in gridview.

    m using c# .net and oracledatabase with 3 tier architecture.

    i want to find the total number of records in the entire gridview.

    M sending the source code of my gridview and the method which i m using to display records in gridview.
    please tell how to do this..

    public void LoadApplication()
    {
    try
    {
    gvApplication.DataSource = null;
    gvApplication.DataBind();
    BLApplication objApplication = new BLApplication();
    DataSet ds = new DataSet();
    objCls = new ClsApplication();
    objCls.supId = Session["USERNAME"].ToString();
    ds = objApplication.GetApplication(objCls);

    if (ds.Tables[0].Rows.Count > 0)
    {
    gvApplication.DataSource = ds;
    gvApplication.DataBind();
    }
    }
    catch (Exception ex)
    {
    lblMessage.Text = ex.Message;
    }
    }


    <asp:GridView ID="gvApplication" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
    AutoGenerateColumns="False" UseAccessibleHeader="False" CssClass="GridRowFormat" AutoGenerateEditButton="true" OnRowDataBound="gvApplication_RowDataBound" OnRowCancelingEdit="gvApplication_RowCancelingEdit" OnRowEditing="gvApplication_RowEditing" OnRowUpdating="gvApplication_RowUpdating" AllowPaging="True" OnPageIndexChanged="gvApplication_PageIndexChanged" OnPageIndexChanging="gvApplication_PageIndexChanging" BorderColor="#404040" BorderStyle="Solid" BorderWidth="2px">
    <HeaderStyle CssClass="DataGridFixedHeader" Wrap="True" Font-Size="Small" />
    <Columns>
    <asp:TemplateField HeaderText="Application Name">
    <ItemTemplate>
    <%# Eval("APPLICATION_NAME") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtAppname" runat="Server" Text='<%# Eval("APPLICATION_NAME") %>'>
    </asp:TextBox>
    <asp:TextBox ID="txtAppnameOld" runat="Server" Text='<%# Eval("APPLICATION_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 FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast"
    NextPageText="Next" PreviousPageText="Prev" />
    </asp:GridView>

  2. #2
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Code:
    // If your datasource is DataSet
    
    DataSet ds=new DataSet();
    
    ds=GetRecords(); // Retrieveing records from database
    lblRecords.Text=ds.Tables[0].Rows.Count; // this is your label displaying total records
    
    Gridview1.DataSource=ds;
    
    Gridview1.DataBind();

    May be This will solve your problem.


    Also check this url http://forums.asp.net/t/1405252.aspx
    thanks,
    kunalraj

  3. #3
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    public void LoadApplication()
    {
    try
    {
    gvApplication.DataSource = null;
    gvApplication.DataBind();
    BLApplication objApplication = new BLApplication();
    DataSet ds = new DataSet();
    objCls = new ClsApplication();
    objCls.supId = Session["USERNAME"].ToString();
    ds = objApplication.GetApplication(objCls);

    if (ds.Tables[0].Rows.Count > 0)
    {
    gvApplication.DataSource = ds;
    gvApplication.DataBind();
    }
    }

    catch (Exception ex)
    {
    lblMessage.Text = ex.Message;
    }
    }

    Code:
    if (ds.Tables[0].Rows.Count > 0)
    {
    lblMessage.Text = ds.Tables[0].Rows.Count;
    gvApplication.DataSource = ds;
    gvApplication.DataBind();
    }
    }

    add this in your code
    thanks,
    kunalraj

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kunalraj View Post
    Hello,

    Code:
    // If your datasource is DataSet
    
    DataSet ds=new DataSet();
    
    ds=GetRecords(); // Retrieveing records from database
    lblRecords.Text=ds.Tables[0].Rows.Count; // this is your label displaying total records
    
    Gridview1.DataSource=ds;
    
    Gridview1.DataBind();

    May be This will solve your problem.


    Also check this url http://forums.asp.net/t/1405252.aspx
    lblMessage.Text = ds.Tables[0].Rows.Count.ToString();

    i did this n got the number of records. but i want to display that in gridview like this....check this link....
    http://www.demohelpdesk.com/main.php?filter=user

    in this gridview it gives 13 entries on the bottom of gridview. Like ths i want to display in my gridview.

  5. #5
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,


    did you check this link http://forums.asp.net/t/1405252.aspx in this you can got your answer.
    check it carefully.
    thanks,
    kunalraj

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kunalraj View Post
    Hello,


    did you check this link http://forums.asp.net/t/1405252.aspx in this you can got your answer.
    check it carefully.
    yes i checked this and many other links...i did showfooter property to true.
    but confused in writing the code in rowdatabound event using footer. In the link it is not properly visible..
    Please guide me what to write in this event.
    protected void gvApplication_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    }

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In label m getting the value of total records. and i did the showfooter property to true.
    Now i want to display this value in the bottom of gridview how to do this? Is there anything to write on gridview rowdatabount event? if yes then please guide.


    if (ds.Tables[0].Rows.Count > 0)
    {
    lblMessage.Text = ds.Tables[0].Rows.Count;
    gvApplication.DataSource = ds;
    gvApplication.DataBind();
    }

  8. #8
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    wild guess i think you have to write this
    Code:
    protected void gvApplication_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataSet ds=new DataSet();
    
         ds=GetRecords(); // Retrieveing records from database
         lblMessage.Text=ds.Tables[0].Rows.Count.ToString(); // this is your label displaying total records
    
        gvApplication.DataSource = ds;
        gvApplication.DataBind();
    }

    hope u got success.
    thanks,
    kunalraj

  9. #9
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you try this one

    Rows: GridView1.Rows.Count

    Columns: GridView1.Columns.Count


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
  •