This is a migrated thread and some comments may be shown as answers.

How to show footer for the columns which are created from codebehind

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
shahid Aleem
Top achievements
Rank 1
shahid Aleem asked on 27 Jul 2010, 09:24 AM
Hello I want to show footer on radgrid. i have populated my radgrid's rows from code behind. there is no control i placed on radgrid but from code behind.

<telerik:RadGrid ID="gvDayWiseCashReport" runat="server" AutoGenerateColumns="False"
                GridLines="None" OnItemDataBound="gvDayWiseCashReport_ItemDataBound">
                <MasterTableView>
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                </MasterTableView>
            </telerik:RadGrid>
in My code behind on button click...This is how i am populating it
protected void btnSearch_Click(object sender, EventArgs e)
    {
        DaysList daysforList = null;
        Month = int.Parse(ddlMonth.SelectedValue);
        Year = int.Parse(ddlYear.SelectedValue);
  
        GetDates dates = new GetDates();
        FirstDate = dates.GetFirstDayOfMonth(Month, Year);
        LastDate = dates.GetLastDayOfMonth(Month, Year);
  
        days = System.DateTime.DaysInMonth(int.Parse(ddlYear.SelectedItem.Value), int.Parse(ddlMonth.SelectedValue)).ToString();
        int NoofDays = int.Parse(days);
  
        DataSet ds = new DataSet();
        DateTime date;
        CustomSQLCommand command = new CustomSQLCommand(@"select distinct Purpose,Others from tbl_CashRequest req left join tbl_CashPurpose purpose
        on purpose.ID=req.CashPurposeID", false);
        ds = command.ExecuteDataSet();
  
        gvDayWiseCashReport.DataSource = null;
        gvDayWiseCashReport.MasterTableView.Columns.Clear();
        gvDayWiseCashReport.DataBind();
  
        gvDayWiseCashReport.DataSource = ds;
  
        GridBoundColumn boundColumn;
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Purpose";
        gvDayWiseCashReport.MasterTableView.Columns.Add(boundColumn);
  
  
        for (int i = 1; i <= NoofDays; i++)
        {
            date = dates.GetDate(int.Parse(ddlMonth.SelectedValue), int.Parse(ddlYear.SelectedItem.Value), i);
            string strDay = date.DayOfWeek.ToString();
            int Day = 0;
            CustomSQLCommand getDay = new CustomSQLCommand(@"select ID from tbl_PreferedTransferDay where PrefferedDay='" + @strDay + "'", false);
            try { Day = int.Parse(getDay.ExecuteScalar()); }
            catch { }
  
            if (Day != 0 && Day != null)
            {
                daysforList = new DaysList();
                GridBoundColumn boundColumn1;
                boundColumn1 = new GridBoundColumn();
  
                boundColumn1.HeaderText = String.Format("{0:ddd, MMM d, yyyy}", date);
                gvDayWiseCashReport.MasterTableView.Columns.Add(boundColumn1);
                daysforList.Day = date;
                daysforList.DayID = Day;
  
                ListDays.Add(daysforList);
            }
            Day = 0;
        }
  
        gvDayWiseCashReport.DataBind();
          
    }
and in item data bound this is how i am writing data on each cell
protected void gvDayWiseCashReport_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
 
            string purpose = "", others = "";
            if (DataBinder.Eval(e.Item.DataItem, "Purpose").ToString() == "Others")
            {
                e.Item.Cells[2].Text = DataBinder.Eval(e.Item.DataItem, "Others").ToString();
                try { purpose = DataBinder.Eval(e.Item.DataItem, "Purpose").ToString(); }
                catch { }
                try { others = DataBinder.Eval(e.Item.DataItem, "Others").ToString(); }
                catch { }
            }
            else
            {
                try { purpose = DataBinder.Eval(e.Item.DataItem, "Purpose").ToString(); }
                catch { }
                others = "";
            }
 
            CustomSQLCommand cmd = new CustomSQLCommand("[SP_CashRequest_getApprovalDayWise]", true);
 
            cmd.AddInputParameter("@Purpose", purpose, SqlDbType.NVarChar, 200);
            cmd.AddInputParameter("@Others", others, SqlDbType.NVarChar, 200);
 
            DataSet ds = cmd.ExecuteDataSet();
 
            for (int j = 0; j < ListDays.Count; j++)
            {
                e.Item.Cells[j + 3].Text = "";
            }
 
            if (ds.Tables[0].Rows.Count > 0)
            {
                int NoofInstallment = 0;
                string InstallmentType = "", PaymentMethod = "";
                int RequestID = 0, ApprovalID = 0; string Remarks = "";
                string RequestedBy = "", ApprovedBy = "";
                float TotalAmount = 0.0F;
 
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    try { NoofInstallment = int.Parse(ds.Tables[0].Rows[i]["NoOfInstallments"].ToString()); }
                    catch { }
                    try { InstallmentType = ds.Tables[0].Rows[i]["ApprovedInstallmentType"].ToString(); }
                    catch { }
                    try { PaymentMethod = ds.Tables[0].Rows[i]["ApprovedPaymentType"].ToString(); }
                    catch { }
                    try { Remarks = ds.Tables[0].Rows[i]["ActionRemarks"].ToString(); }
                    catch { }
                    try { ApprovedBy = ds.Tables[0].Rows[i]["ActionTakenBy"].ToString(); }
                    catch { }
                    try { RequestedBy = ds.Tables[0].Rows[i]["RequesterName"].ToString(); }
                    catch { }
                    try { TotalAmount = int.Parse(ds.Tables[0].Rows[i]["ApprovedAmount"].ToString()); }
                    catch { }
                    try { ApprovalID = int.Parse(ds.Tables[0].Rows[i]["ApprovalID"].ToString()); }
                    catch { }
 
                    cfmsBL.ApprovalID = ApprovalID;
 
                    #region Single Installments
                    if (PaymentMethod == "Single time")
                    {
                        DateTime CashTransferDay = DateTime.MinValue;
                        float Amount = 0.0F;
                        String TransferDayIDs = "";
                        try { TransferDayIDs = ds.Tables[0].Rows[i]["ApprovedTransferDayIDs"].ToString(); }
                        catch { }
                        try { CashTransferDay = DateTime.Parse(ds.Tables[0].Rows[i]["ApprovedCashTransferDay"].ToString()); }
                        catch { }
 
                        DataSet dsTransfer = new DataSet();
 
                        if (TransferDayIDs != "" && TransferDayIDs != null)
                        {
                            DataSet dsTransferDays = DB.CFMS_DB.GetByIDs(TransferDayIDs);
                            if (dsTransferDays.Tables[0].Rows.Count > 0)
                            {
                                TransferDayIDs = "";
                                for (int k = 0; k < dsTransferDays.Tables[0].Rows.Count; k++)
                                {
                                    try { TransferDayIDs = TransferDayIDs + dsTransferDays.Tables[0].Rows[k]["PrefferedDay"].ToString() + ","; }
                                    catch { }
                                }
                                TransferDayIDs = TransferDayIDs.Substring(0, TransferDayIDs.Length - 1);
                            }
                            cfmsBL.DaysName = TransferDayIDs.Split(',');
                        }
 
                         
 
 
                        for (int j = 0; j < ListDays.Count; j++)
                        {
                            cfmsBL.Dates = "";
                            DateTime dateNext = DateTime.MinValue;
                            DateTime dateCurr = DateTime.MinValue;
                            dateCurr = ListDays[j].Day;
                            try { dateNext = ListDays[j + 1].Day; }
                            catch { }
                            if (CashTransferDay == ListDays[j].Day)
                            {
                                if (e.Item.Cells[j + 3].Text == "")
                                {
                                    try { Amount = int.Parse(ds.Tables[0].Rows[i]["ApprovedAmount"].ToString()); }
                                    catch { }
                                }
                                else
                                {
                                    try { Amount = float.Parse(e.Item.Cells[j + 3].Text.ToString()) + float.Parse(ds.Tables[0].Rows[i]["ApprovedAmount"].ToString()); }
                                    catch { }
                                }
                                try { e.Item.Cells[j + 3].Text = Amount.ToString(); }
                                catch { }
}
}
}
Now i want to show the summ of each column on footer. please tell me how to acheive this. I have attached the snap of the grid.

1 Answer, 1 is accepted

Sort by
0
shahid Aleem
Top achievements
Rank 1
answered on 27 Jul 2010, 11:45 AM
Sorry guys....

I got the solution... Its very easy but due pressure could not understand....
rotate loop
footer.cells[i].Text="value";
Tags
General Discussions
Asked by
shahid Aleem
Top achievements
Rank 1
Answers by
shahid Aleem
Top achievements
Rank 1
Share this question
or