如何在使用分页时获取gridview所有行数据。 [英] how to get gridview all rows data when using paging.

查看:86
本文介绍了如何在使用分页时获取gridview所有行数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家



我有一个带分页的网格视图(页面大小10),其中包含课程详细信息。当我将gridview数据保存到数据库时,它只保存10条记录(根据页面)。

是否可以获得所有gridview所有行。

例如如果我的gridview包含25行分页,当我将数据保存到数据库中时,所有25行数据都插入到数据库中?

请使用...

我的代码


Hi experts

I have a gridview with paging (page size 10), which contains Course details. when i am saving gridview data into database it save only 10 record (according to page).
is there any to get all gridview all rows.
e.g. if my gridview contains 25 rows with paging and when i save data into database then all 25 rows data insert into database?
please hepl...
my code

 protected void button_Click(object s, EventArg e)
 {
        foreach (GridViewRow row in gvExportCourse.Rows)
        {
            Label exCourse = (Label)row.FindControl("gvlblCourseName");
            Label exUniversityCourse = (Label)row.FindControl("gvlblUniversityCourseName");
            if (exCourse != null)
            {
               if (!string.IsNullOrEmpty(exCourse.Text))
               {
                    CourseInformation course = new CourseInformation();
                    course.AddCourseMaster(exCourse.Text, exUniversityCourse.Text);
               }
            }
        }
        label1.Text = "Course saved successfully.";
}





forx为您提供帮助。



thanx in advanced for you help.

推荐答案

您需要在GrIdView的PageIndexChanging事件中将数据保存在临时存储中。在最终保存时,将数据表发送到Sql Server Procedure或循环遍历数据表并将其保存在数据库中。按照以下步骤操作:

在PageIndexChanging事件:

You need to save the data in temporary storage in PageIndexChanging event of GrIdView. On final save send the datatable to Sql Server Procedure or loop through the datatable and save it in database. Follow the steps:
In PageIndexChanging Event:
protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    fnStoreGridData();
}
private void fnStoreGridData()
{
    DataTable TempDataTable = new DataTable();
    if(Session["Data"]!=null){
        TempDataTable = Session["Data"] as DataTable;
    }
    else{
        TempDataTable.Columns.Add("exCourse", typeof(string)) ;
        TempDataTable.Columns.Add("exUniversityCourse", typeof(string)) ;
    }
    foreach (GridViewRow row in gvExportCourse.Rows)
    {
        Label exCourse = (Label)row.FindControl("gvlblCourseName");
        Label exUniversityCourse = (Label)row.FindControl("gvlblUniversityCourseName");
        if (exCourse != null)
        {
           if (!string.IsNullOrEmpty(exCourse.Text))
           {
                TempDataTable.Rows.Add(exCourse.Text, exUniversityCourse.Text);
                //TempDataTable is your datatable object. Make sure that datatable contains these columns
           }
        }
    }
}



最后保存:


In Final Save:

protected void button_Click(object s, EventArg e)
{
    fnStoreGridData(); //Here this will bind the data of current page
    DataTable TempDataTable = new DataTable();
    if(Session["Data"]!=null){
        TempDataTable = Session["Data"] as DataTable;
    }
    //Now loop through datatable and store the values
    foreach(DataRow in TempDataTable.Rows)
    {
        CourseInformation course = new CourseInformation();
        course.AddCourseMaster(dr["exCourse"].ToString(), dr["exUniversityCourse"].ToString());
    }
    label1.Text = "Course saved successfully.";
}







--Amit




--Amit


这篇关于如何在使用分页时获取gridview所有行数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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