Sunday 2 September 2012

How to Group Gird Row Wise








 protected void GvGatePassSummary_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           

            if (e.Row.RowType == DataControlRowType.DataRow)
            {   //We're only interested in Rows that contain data
                //get a reference to the data used to databound the row


                DataRowView drv = ((DataRowView)e.Row.DataItem);
                if (previousCat == drv["GatePassNo"].ToString() && GatePassDate == drv["GatePassDate"].ToString())
                {
                    //If it's the same category as the previous one
                    //Increment the rowspan
                    if (GvGatePassSummary.Rows[firstRow].Cells[0].RowSpan == 0)
                        GvGatePassSummary.Rows[firstRow].Cells[0].RowSpan = 2;
                    else
                        GvGatePassSummary.Rows[firstRow].Cells[0].RowSpan += 1;
                    e.Row.Cells.RemoveAt(0);


                    if (GvGatePassSummary.Rows[firstRow].Cells[1].RowSpan == 0)
                        GvGatePassSummary.Rows[firstRow].Cells[1].RowSpan = 2;
                    else
                        GvGatePassSummary.Rows[firstRow].Cells[1].RowSpan += 1;
                    //Remove the cell                
                    e.Row.Cells.RemoveAt(0);

                    if (GvGatePassSummary.Rows[firstRow].Cells[2].RowSpan == 0)
                        GvGatePassSummary.Rows[firstRow].Cells[2].RowSpan = 2;
                    else
                        GvGatePassSummary.Rows[firstRow].Cells[2].RowSpan += 1;
                    //Remove the cell                
                    e.Row.Cells.RemoveAt(1);
                }
                //if (GatePassDate == drv["GatePassDate"].ToString())
                //{
                //    if (GvGatePassSummary.Rows[firstRow].Cells[1].RowSpan == 0)
                //        GvGatePassSummary.Rows[firstRow].Cells[1].RowSpan = 2;
                //    else
                //        GvGatePassSummary.Rows[firstRow].Cells[1].RowSpan += 1;
                //    //Remove the cell                
                //    e.Row.Cells.RemoveAt(0);
                //}
                // GatePassDate == drv["GatePassDate"].ToString()
                else //It's a new category
                {                //Set the vertical alignment to top
                    e.Row.VerticalAlign = VerticalAlign.Middle;
                    //Maintain the category in memory
                    previousCat = drv["GatePassNo"].ToString();
                    GatePassDate = drv["GatePassDate"].ToString();
                    CustName = drv["PartyName"].ToString();
                    firstRow = e.Row.RowIndex;
                }
            }
     
        }

No comments:

Post a Comment

Contact Us:

Email:

Vinodkumar434@gmail.com,
vinodtechnosoft@gmail.com

Skype Name:

vinodtechnosoft