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

problem in gridView

2 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
karyjon
Top achievements
Rank 1
karyjon asked on 15 Mar 2010, 03:22 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Mar 2010, 08:06 AM
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
0
karyjon
Top achievements
Rank 1
answered on 16 Mar 2010, 08:23 AM
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();
        }



Tags
Grid
Asked by
karyjon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
karyjon
Top achievements
Rank 1
Share this question
or