Gridview分页不允许访问网格中的所有行

Gridview分页不允许访问网格中的所有行

本文介绍了Gridview分页不允许访问网格中的所有行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码...

My Code...

Static datatable data;
protected void Page_Load(object sender, EventArgs e)
   {
       
       if (!IsPostBack)
       {
           data = new DataTable();
           CalculatePURID();
           loadgrid();
       }

   }

public DataTable Fill()
    {
        DataTable dt = new DataTable("items");
        dt.Columns.Add("sno", typeof(int));
        dt.Columns.Add("Prod_id", typeof(string));
        dt.Columns.Add("Prod_name", typeof(string));
        dt.Columns.Add("Prod_size", typeof(string));
        dt.Columns.Add("Prod_qty", typeof(string));
        dt.Columns.Add("Prod_Per_amt", typeof(string));
        dt.Columns.Add("Prod_amt", typeof(string));

        foreach (GridViewRow grdRow in Grid_Purchase.Rows)        
        {
            int i = grdRow.RowIndex;
            DataRow dr = dt.NewRow();
            System.Web.UI.WebControls.Label txt_sno = (System.Web.UI.WebControls.Label)(Grid_Purchase.Rows[i].FindControl("lblsno"));
            System.Web.UI.WebControls.TextBox txt_Prodid = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_Pid"));
            System.Web.UI.WebControls.DropDownList txt_Prodname = (System.Web.UI.WebControls.DropDownList)(Grid_Purchase.Rows[i].FindControl("txt_grd_ProdName"));
            System.Web.UI.WebControls.TextBox txt_Prodsize = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_size"));
            System.Web.UI.WebControls.TextBox txt_Prodqty = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_qty"));
            System.Web.UI.WebControls.TextBox txt_Prodperamt = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_piece_amt"));
            System.Web.UI.WebControls.TextBox txt_Prodamt = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_amt"));

            dr[0] = txt_sno.Text.ToString();
            dr[1] = txt_Prodid.Text.ToString();
            dr[2] = txt_Prodname.Text.ToString();
            dr[3] = txt_Prodsize.Text.ToString();
            dr[4] = txt_Prodqty.Text.ToString();
            dr[5] = txt_Prodperamt.Text.ToString();
            dr[6] = txt_Prodamt.Text.ToString();
            dt.Rows.Add(dr);
        }
       
        return dt;
    }


public DataTable FillNewrow()
    {
        
        int a = totalnumberofrowsin_Grid;
        data = Fill();      //To get previous values       
        
        DataRow dr1 = data.NewRow();
        dr1[0] = a+1;
        dr1[1] = "";
        dr1[2] = "";
        dr1[3] = "";
        dr1[4] = "";
        dr1[5] = "";
        dr1[6] = "";
        data.Rows.InsertAt(dr1, a + 1);        
        
        //ds.Tables.Add(data);
        
        totalnumberofrowsin_Grid++;
        return data;
    }
    


protected void Grid_Purchase_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       Grid_Purchase.PageIndex = e.NewPageIndex;
       Grid_Purchase.DataSource = data;   <b>// Even i used static datatable containing datas(I saw the data using breakpoint).</b>
       Grid_Purchase.DataBind();
   }


protected void Lnk_insert_Click(object sender, EventArgs e)   //link button inside footer of grid
    {
        DataTable dt = new DataTable();
        dt = FillNewrow();
        
        Grid_Purchase.DataSource = dt;
        Grid_Purchase.DataBind();
        DataTable myDatatable1 = new DataTable();
        myDatatable1 = SQLobj.SQL_Adapter("select Prod_name from ProductDetails");
        DropDownList drdList;
        DataRow dr2;
        dr2 = myDatatable1.NewRow();
        dr2["Prod_name"] = "-Select-";
        myDatatable1.Rows.InsertAt(dr2, 0);
        foreach (GridViewRow grdRow in Grid_Purchase.Rows)
        {
            drdList = (DropDownList)(Grid_Purchase.Rows[grdRow.RowIndex].Cells[1].FindControl("txt_grd_ProdName"));
            drdList.DataSource = myDatatable1;
            drdList.DataTextField = "Prod_name";
            drdList.DataBind();
        }
    }


protected void Grid_Purchase_RowCommand(object sender, GridViewCommandEventArgs e) //i just fired it for paging
    {

    }

推荐答案




这篇关于Gridview分页不允许访问网格中的所有行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 14:45