problem in gridView

3 posts, 0 answers
  1. karyjon
    karyjon avatar
    6 posts
    Member since:
    Oct 2012

    Posted 15 Mar 2010 Link to this post

    hi
    i have two problem with telerik.grid
    first please look at my code

    private void loadGridView()
            {
                grdIODump.DataSource = IOInfo.personIOInfo(Session["perno"].ToString(), txtbeginDate.Text, txtEndDate.Text);
                grdIODump.DataBind();
            }

    i call this code in my submit button function;
    and this is my grid code:
    <telerik:RadGrid runat="server" ID="grdIODump" Skin="Black"  
            AutoGenerateColumns="False" GridLines="None" 
            AllowPaging="True" AllowSorting="True" PageSize="31"  
            GroupingEnabled="False" Font-Names="Tahoma" Font-Size="10pt"
         
        <MasterTableView NoMasterRecordsText="اطلاعاتی برای نمایش موجود نمی باشد"
            <Columns> 
                <telerik:GridBoundColumn DataField="enterDayName" HeaderText="روز ورود"  
                    UniqueName="enterDayName" AllowSorting="False"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="BEGINDATE" HeaderText="تاریخ ورود"  
                    UniqueName="BEGINDATE"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
                   <telerik:GridBoundColumn DataField="BEGINTIME" HeaderText=" ساعت ورود"  
                    UniqueName="BEGINTIME" AllowSorting="false"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
                   <telerik:GridBoundColumn DataField="exitDayName" HeaderText="روز خروج"  
                    UniqueName="exitDayName" AllowSorting="False"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
                  <telerik:GridBoundColumn DataField="ENDDATE" HeaderText="تاریخ خروج"  
                    UniqueName="ENDDATE" AllowSorting="False"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
                  <telerik:GridBoundColumn DataField="ENDTIME" HeaderText="ساعت خروج"  
                    UniqueName="ENDTIME" AllowSorting="False"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
                  <telerik:GridBoundColumn DataField="DURATION" HeaderText="میزان کارکرد"  
                    UniqueName="DURATION"
                    <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                    <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" /> 
                </telerik:GridBoundColumn> 
            </Columns> 
             
        </MasterTableView> 
        <ClientSettings ReorderColumnsOnClient="True"
        </ClientSettings> 
         
    </telerik:RadGrid> 
    and now my problem:
    1- when i click on one of header to sort my grid go disapear. but if i load grid view in my page_load too it does not but i can't load this in page_load.
    2- if i write this code in my oadGridView() function

                for (int i = 0; i < grdIODump.Items.Count; i++)
                {
                    if (grdIODump.Items[i]["DURATION"].Text == "۰۰:۰۰")
                    {
                        grdIODump.Items[i].BackColor = System.Drawing.Color.Pink;
                    }
                }
    // change bg color of some row in if statement
    it works just for first page of my grid and in the other page it doesn't work

    can any one help me????



  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Mar 2010 Link to this post

    Hello,

    Problem 1: One suggestion would be using Advanced Data Binding for RadGrid than simple data binding.
    Initially set the Visible property of RadGrid to "false" and change the value in Button1_Click event and invoke Rebind() method, which in turn call the NeedDataSource event to populate the grid.

    C#:
     
    protected void Button1_Click(object sender, EventArgs e) 
        grdIODump.Visible = true// Set the Visibility of grid 
        grdIODump.Rebind();  
     
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
        loadGridView(); 
     
    private void loadGridView() 
         grdIODump.DataSource = IOInfo.personIOInfo(Session["perno"].ToString(), txtbeginDate.Text, txtEndDate.Text); 

    Problem2: To change the background color of the particular cell, use the following code in ItemDataBound event.

    C#:

    protected
     void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
            { 
                if (e.Item is GridDataItem) 
                { 
                    GridDataItem Item = (GridDataItem)e.Item; 
                    if (Item["DURATION"].Text == "۰۰:۰۰"
                    { 
                            Item["DURATION"].BackColor = System.Drawing.Color.Pink; 
                    }                
                } 
            } 

    -Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. karyjon
    karyjon avatar
    6 posts
    Member since:
    Oct 2012

    Posted 16 Mar 2010 Link to this post

    i solve it.
    i add these codes:

            protected void grdIODump_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
            {
                loadGridView();
            }

            protected void grdIODump_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
            {
                loadGridView();
            }



Back to Top