如何在GridView中计算记录 [英] How to Count Records in GridView

查看:101
本文介绍了如何在GridView中计算记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是



如何在GridView中记录记录,我拿了一个链接按钮& linkbutton的文本是申请人,但我希望展示申请人数(计数申请人)而不是写申请人。



编码

UI代码

Hi,My Question is

How to Count Records in GridView,I took one link button & text of linkbutton is applicants,but i want number of applicants(count applicants)should be display instead of writing applicants.

Coding
UI Code

public partial class Job_Response : System.Web.UI.Page
{
    static DataTable dt;
    ResponseDetail_select responseobj = new ResponseDetail_select(ConfigurationManager.ConnectionStrings["portal"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dt = responseobj.get_response_job(cmp_id);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}





Class.cs



Class.cs

public DataTable get_response_job(int cmp_id)
{
  return (dl.GetDataTable("select job_id,job_title from Recruiter_JobPost where company_id='" + cmp_id + "'"));
}





源代码



Source Code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

                DataKeyNames="job_id" onselectedindexchanged="GridView1_SelectedIndexChanged" 

                Height="204px" Width="819px" onrowcommand="GridView1_RowCommand" 

                BorderColor="#0099FF" BorderStyle="Outset" CellPadding="4" ForeColor="#333333" 

                GridLines="None" style="margin-left: 85px" >
        <alternatingrowstyle backcolor="White" />
        <columns>
<asp:BoundField DataField="job_title" HeaderText="Job Title" SortExpression="job_title" />
            <asp:TemplateField HeaderText="No of Applicants" SortExpression="total_applicants">
                
                <itemtemplate>
                    <asp:LinkButton ID="LinkButtonApp" runat="server" CommandName="App" CommandArgument='<%#Eval("job_id")%>' >Applicants
                </itemtemplate>
            
</columns>

推荐答案

如果绑定DataTable( dt )对于GridView,您可以使用 Rows.Count 属性 dt



If you bind DataTable (dt) to your GridView, you can use Rows.Count property for dt.

Label1.Text = "Rows count: " + dt.Rows.Count.ToString();





简单?



Simple?


http://forums.asp.net/t/986566.aspx [ ^ ]


我会尝试这样的事情:

I would try something like this:
int i = 0;

foreach(DataRow dr in dt.Rows)
{
    i++;
}



这只是计算将填充GridView的行的一种简单方法。


It is just a simple way to count the rows that will be filling your GridView.


这篇关于如何在GridView中计算记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆