Formating cells of autogenerated column in radgrid

2 posts, 0 answers
  1. Purojit
    Purojit avatar
    26 posts
    Member since:
    Jun 2013

    Posted 14 Jun 2013 Link to this post

    Requirements

    RadControls version
    .NET version
    Visual Studio version
    programming language
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION

    We have a rad grid with auto generated column. In some of the column (those that are having numeric data in the column should be right aligned. We have tried from our end by following your code from the forum.But could be able to accomplish  desired result. Below we are providing the .aspx and .cs files and also the snapshot of the grid.
    .aspx

    <%@ Page Language="C#" MasterPageFile="~/Presentationlayer/MasterAdmin.master" AutoEventWireup="true" CodeFile="T_Other_AgentwiseCaseStatement.aspx.cs" Inherits="Presentationlayer_TAgentwiseCaseStatement" Title="Agentwise Case Statement" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register Src="MS_Control/MultipleSelection.ascx" TagName="MultipleSelection" TagPrefix="uc1" %>   


    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
         <div>
         
    <script type="text/javascript">
        function pageLoad() {
            var grid = $find('<%=RadGrid1.ClientID %>');
            var columns = grid.get_masterTableView().get_columns();
            for (var i = 0; i < columns.length; i++) {
                columns[i].resizeToFit();
            }
        }
    </script>
    </div>
         <div>
         
         
                 <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="True"  
                    AllowSorting="true" AllowPaging="True" PageSize="50" Skin="Sunset"
                    ShowFooter="True" AllowFilteringByColumn="true" ShowGroupPanel="true"
                     onneeddatasource="RadGrid1_NeedDataSource" OnColumnCreated ="RadGrid1_ColumnCreated" >  <%--OnColumnCreated ="RadGrid1_ColumnCreated --%>
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Sunset"></HeaderContextMenu>

                    <ExportSettings HideStructureColumns="true" IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true" />
                    <MasterTableView CommandItemDisplay="Top" ShowGroupFooter="true" GroupLoadMode="Client" TableLayout="Fixed" Width="100%">
                    <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true"
                        ShowExportToCsvButton="true" ShowExportToPdfButton="true" ShowAddNewRecordButton="false" />
                                       
    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>

    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>

    <EditFormSettings>
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
                                       
                    </MasterTableView>
                    <ClientSettings Selecting-AllowRowSelect="true" AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true" EnableRowHoverStyle="true" AllowGroupExpandCollapse="true" ReorderColumnsOnClient="True" AllowDragToGroup="true" AllowColumnsReorder="True">
    <Selecting AllowRowSelect="True"></Selecting>
    <Scrolling AllowScroll="false" UseStaticHeaders="true" />
                        <Resizing AllowColumnResize="true" EnableRealTimeResize="true" AllowResizeToFit="true" />
                    </ClientSettings>
                    <FilterMenu EnableImageSprites="False"></FilterMenu>
                </telerik:RadGrid>  
            </div>
           <div>
            <telerik:RadDock ID="RadDock1" runat="server" Width="380px" Left="10" Top="125"
                 Title="Search Companion"  DefaultCommands="ExpandCollapse">
                <ContentTemplate>
                    <table>
                        
                        <tr>
                        <td>
                        <table width="90%">
                           <tr>
                            <td> From</td>
                            <td>
                                <telerik:RadDatePicker ID="rdpFrom" runat="server" Width="100"  Culture="(Default)">
                                    <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x" Skin="Outlook"></Calendar>

                                    <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>

                                    <DateInput DisplayDateFormat="dd/MM/yyyy"    AutoPostBack="False"></DateInput>
                                </telerik:RadDatePicker>
                            </td>
                            <td> To</td>
                            <td>
                                <telerik:RadDatePicker ID="rdpTo" runat="server" Width="100"  Culture="(Default)">
                                    <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x" Skin="Outlook"></Calendar>

                                        <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>

                                        <DateInput DisplayDateFormat="dd/MM/yyyy"    AutoPostBack="False"></DateInput>
                                </telerik:RadDatePicker>
                            </td>
                        </tr>
                        </table>
                             
                            </td>
                        </tr>
                         <tr>
                                    <td style="z-index:2">
                                <asp:CheckBox ID="CheckBox1" runat="server" Text="All/Selective Agent" Checked="true"
                                    AutoPostBack="true" oncheckedchanged="CheckBox1_CheckedChanged" />
                                <br />
                                <uc1:MultipleSelection ID="chkAgent" runat="server" width="400px" />
                            </td></tr>
                      
                        <tr>
                         <td colspan="1">
                        <table width="50%">
                           <tr>
                            
                                    <td>
                                        Print Company Name,Address &amp; Report Heading :
                                    </td>
                                    <td>
                                        <telerik:RadComboBox ID="ddlincldagentcase" runat="server" Width="60PX">
                                            <Items>
                                                <telerik:RadComboBoxItem Text="Yes" Value="Y" />
                                                <telerik:RadComboBoxItem Selected="true" Text="No" Value="N" />
                                            </Items>
                                        </telerik:RadComboBox>
                                    </td>
                                    </tr>
                                    </table>
                                    </td>  
                                
                        </tr>
                        </tr>
                        <caption>
                            <br />
                            <br />
                            <tr>
                                <td>
                                    <table width="75%">
                                        <tr>
                                            <td align="left">
                                                <telerik:RadButton ID="rbtRpt" runat="server" onclick="rbtRpt_Click"
                                                    Text="Print">
                                                </telerik:RadButton>
                                            </td>
                                            <td align="right">
                                                <telerik:RadButton ID="rbtShow" runat="server" onclick="rbtShow_Click"
                                                    Text="Preview">
                                                </telerik:RadButton>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </caption>
                        </tr>
                    </table>
                </ContentTemplate>
            </telerik:RadDock>
              <%--<asp:SqlDataSource ID="SqlDataSource2" ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT name as DOCTORNAME FROM doctor"
        runat="server"></asp:SqlDataSource>--%>
        </div>
    </asp:Content>

    .cs

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Web.Configuration;
    using System.Data.SqlClient;
    using System.Globalization;
    using Telerik.Web.UI;


    public partial class Presentationlayer_TAgentwiseCaseStatement : System.Web.UI.Page
    {
        string conn;

        Binddata btd;

        Misc1 misc;
        string strfltr1;

        public void conns()
        {

            conn = WebConfigurationManager.ConnectionStrings[Convert.ToString(Session["connstring"])].ConnectionString;
        }
        public void reset()
        {

            misc = new Misc1();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToString(Session["connstring"]) == "" || Convert.ToString(Session["connstring"]) == null)
            {
                Response.Redirect("Userauthentication.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    btd = new Binddata();
                    ViewState["crdate"] = btd.getsrdate();
                    ViewState["fnstartdate"] = Convert.ToString(Session["fnstartdate"]);
                    ViewState["mode"] = "0";
                    string opdt = "01/04/" + Convert.ToString(ViewState["fnstartdate"]);
                    rdpFrom.SelectedDate = DateTime.Parse(ViewState["fnstartdate"].ToString(), CultureInfo.CreateSpecificCulture("en-CA")); ;
                    chkAgent.Visible = false;

                    rdpTo.SelectedDate = DateTime.Parse(ViewState["crdate"].ToString(), CultureInfo.CreateSpecificCulture("en-CA")); ;
                    //ViewState["ch"] = "1";
                    //bindgrid();
                    //RadGrid1.DataBind();
                    //RadDock1.Collapsed = true;
                }
            }
        }
        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            if (Convert.ToString(ViewState["mode"]) == "1")
            {
                bindgrid();
            }

            

        }

        private void bindgrid()
        {
            conns();
            SqlConnection con = new SqlConnection(conn);
            SqlCommand com;
            try
            {
                //ViewState["cmpid"] = "1";
                con.Open();
                com = new SqlCommand("Usp_AgentwiseCasestmt", con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@ComCode", "");
                com.Parameters.AddWithValue("@FrmDt", DateTime.Parse(rdpFrom.SelectedDate.Value.ToString("yyyy/MM/dd"), CultureInfo.CreateSpecificCulture("en-CA")));
                com.Parameters.AddWithValue("@ToDt", DateTime.Parse(rdpTo.SelectedDate.Value.ToString("yyyy/MM/dd"), CultureInfo.CreateSpecificCulture("en-CA")));
                // com.Parameters.AddWithValue("@ch", Int32.Parse(Convert.ToString(ViewState["ch"])));
                com.Parameters.AddWithValue("@strfltr", Convert.ToString(ViewState["strfltr"]));
                // com.Parameters.AddWithValue("@Pending", ddlonlypending.SelectedValue);
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataTable dt = new DataTable();
                da.Fill(dt);
                RadGrid1.MasterTableView.Caption = "AgentWise CaseStatement   " + rdpFrom.SelectedDate.Value.ToString("dd/MM/yyyy") + " To" + rdpTo.SelectedDate.Value.ToString("dd/MM/yyyy");
                //int x = com.ExecuteNonQuery();
                RadGrid1.DataSource = dt;
                RadGrid1.DataBind();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                con.Close();

            }

        }
        protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            /


        }
        protected void rbtShow_Click(object sender, EventArgs e)
        {
            ViewState["mode"] = "1";
            if (chkAgent.sValue != "")
            {
                strfltr1 = " and AGENT.CODE IN(" + chkAgent.sValue + ") ";
            }
            else
            {
                strfltr1 = "";
            }
            ViewState["strfltr"] = strfltr1;
            bindgrid();
            RadGrid1.DataBind();
            RadDock1.Collapsed = true;
        }
        protected void rbtRpt_Click(object sender, EventArgs e)
        {

            Response.Write("<script>window.open('T_Other_AgentwiseCaseStatement_rpt.aspx?cmp=" + Convert.ToString(ViewState["cmpid"]) + "&dtfrom=" + rdpFrom.SelectedDate.Value.ToString("dd/MM/yyyy") + "&dtto=" + rdpTo.SelectedDate.Value.ToString("dd/MM/yyyy") + "&strfltr=" + Convert.ToString(ViewState["strfilter"]) + "', '','left=0,height=900,width=1200,top=0,resizable=no,scrollbars=yes,toolbar=no,status=no,target=_blank,location=no');</script>");

        }
        protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column.ColumnType== "GridBoundColumn")
            {
                if (e.Column.UniqueName != "patient" && e.Column.UniqueName != "Agent" && e.Column.UniqueName != "casedt" && e.Column.UniqueName != "CaseNo")
                {
                    e.Column.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                    e.Column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                }
                if (e.Column.DataType == typeof(String))
                {
                    e.Column.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
                    e.Column.HeaderStyle.HorizontalAlign = HorizontalAlign.Left;

                }
               
                
                  
               
            }
           

        }
       
     
        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox1.Checked == true)
            {
                chkAgent.Visible = false;
                
            }
            else
            {
                chkAgent.Visible = true;
                bindagent();
                

            }
        }
        public void bindagent()
        {
            conns();
            SqlConnection con = new SqlConnection(conn);
            SqlCommand com;
            con.Open();
            com = new SqlCommand("Select CODE, NAME from AGENT Order by Name", con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            da.Fill(dt);
            chkAgent.CreateCheckBox(dt, "name", "code");
        }
    }





    Thanks and Regards
    Purojit

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 18 Jun 2013 Link to this post

    Hello Purojit,

    Please note that the Code Library type of tickets are for the customers to share their applications which presents useful scenarios and which could be approved as Code Libraries uploaded to our site.

    Therefore in case you are facing technical issues with our controls please open a regular support ticket or a forum post so that we could address your issues properly.

    Regards,
    Maria Ilieva
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top