?
Solved

Radgrid displays data only after the first postback ...

Posted on 2009-12-22
16
Medium Priority
?
5,864 Views
Last Modified: 2012-06-27
Hello. I have the following issue, the data in the grid are displayed correctly but after the first refresh the page. How to make that data were displayed in the grid as soon as the page loads?

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="raport_urlopy.aspx.vb" Inherits="raport_urlopy" %>  
  
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  
<html xmlns="http://www.w3.org/1999/xhtml">   
<head runat="server">   
    <title>Intranet</title>  
</head>  
<body>  
    <form id="form1" runat="server">   
       
    <div class="gora"><a href="default.aspx"><img src="gfx/intranet2.gif" alt="Intranet" border="0"></a>  
    </div>  
       
    <div class="menu">   
   <!-- #include file="inc-menu.aspx "-->       
         
    </div>  
       
    <div class="srodek">   
       
      
    <asp:ScriptManager ID="ScriptManager1" runat="server">   
    </asp:ScriptManager>  
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">   
        </telerik:RadAjaxManager>  
       
       <div style="text-align:left">   
       <div class="pasek">Raport o urlopach</div>  
       <table border="0">   
       <tr>  
       <td align="right" valign="middle">Rok:</td><td align="left" valign="middle">   
          
         <asp:DropDownList ID="ddl_rok" runat="server" DataSourceID="sql_rok"    
                            DataTextField="kp_rok" DataValueField="kp_rok" Width="258px" AutoPostBack="True">   
         </asp:DropDownList>  
          
       </td>  
       </tr>  
          
       <tr>  
       <td align="right" valign="middle">DziaB:</td><td align="left" valign="middle">   
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sql_dzial"    
                            DataTextField="nazdz" DataValueField="id" Width="258px" AutoPostBack="True"></asp:DropDownList></td>   
       </tr>  
                 
       </table>  
          
    </div>  
          
            <asp:TextBox ID="txt_idp" runat="server" Visible="False"></asp:TextBox>  
          
        <br />       
        
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="sql_urlopy_glowne"    
            GridLines="None" AllowSorting="True" ShowGroupPanel="True" Skin="Hay" allow>  
         
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="idp" DataSourceID="sql_urlopy_glowne">   
                <DetailTables>  
                    <telerik:GridTableView AutoGenerateColumns="false" DataKeyNames="idp" DataSourceID="sql_urlopy_pomoc" Width="100%" runat="server">   
                                             
                        <ParentTableRelation>  
                            <telerik:GridRelationFields DetailKeyField="idp" MasterKeyField="idp" />  
                        </ParentTableRelation>  
                        <Columns>  
                            <telerik:GridBoundColumn SortExpression="opis" HeaderText="Typ" DataField="opis" UniqueName="opis">   
                            </telerik:GridBoundColumn>  
                               
                             <telerik:GridBoundColumn SortExpression="pdn" HeaderText="Od" DataField="pdn" UniqueName="pdn"  DataFormatString="{0:dd-MM-yyyy}">   
                            </telerik:GridBoundColumn>  
                               
                              <telerik:GridBoundColumn SortExpression="odn" HeaderText="Do" DataField="odn" UniqueName="odn"  DataFormatString="{0:dd-MM-yyyy}">   
                            </telerik:GridBoundColumn>  
                        </Columns>  
                                      
                    </telerik:GridTableView>  
                </DetailTables>  
  
<ExpandCollapseColumn Visible="True"></ExpandCollapseColumn>  
  
                <Columns>  
                    <telerik:GridBoundColumn DataField="idp" DataType="System.Int32" HeaderText="idp"  
                        ReadOnly="True" SortExpression="idp" UniqueName="idp" Visible="false">   
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="naz" HeaderText="Nazwisko" SortExpression="naz" UniqueName="naz">   
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="IL_UrlopWymiar" DataType="System.Int16" HeaderText="Wymiar"  
                        SortExpression="IL_UrlopWymiar" UniqueName="IL_UrlopWymiar">   
                    </telerik:GridBoundColumn>  
                      
                    <telerik:GridBoundColumn DataField="KD_IL_UrlopPrzysl" DataType="System.Int16" HeaderText="PrzysBugujcy"  
                        SortExpression="KD_IL_UrlopPrzysl" UniqueName="KD_IL_UrlopPrzysl">   
                    </telerik:GridBoundColumn>  
                       
                     <telerik:GridBoundColumn DataField="IL_UrlopDoWyk" DataType="System.Int16" HeaderText="PozostaBy"  
                        SortExpression="IL_UrlopDoWyk" UniqueName="IL_UrlopDoWyk">   
                    </telerik:GridBoundColumn>  
                </Columns>  
            </MasterTableView>  
            <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True"    
                ReorderColumnsOnClient="True">   
                <Selecting AllowRowSelect="True" />  
            </ClientSettings>  
        </telerik:RadGrid>  
                             
        <br /><br /><br />  
                      
    </div>  
       
       
    <asp:SqlDataSource ID="sql_dzial" runat="server"    
        ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"    
        SelectCommand="proc_wczytaj_dzialy" SelectCommandType="StoredProcedure">   
      
       <SelectParameters>  
        
           <asp:FormParameter DefaultValue="122" FormField="txt_idp" Name="idpracownika"    
               Type="Int32" />  
        
        
       </SelectParameters>         
               
     </asp:SqlDataSource>  
      
    <asp:SqlDataSource ID="sql_urlopy_glowne" runat="server"    
        ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"    
        SelectCommand="proc_pokaz_ilosc_urlopow_w_dziale"    
        SelectCommandType="StoredProcedure">   
           
        <SelectParameters>  
         
            <asp:ControlParameter ControlID="DropDownList1" Name="id_dzial"    
                PropertyName="SelectedValue" Type="Int32" />  
           
             <asp:ControlParameter ControlID="ddl_rok" Name="rok"    
                PropertyName="SelectedValue" Type="Int32" />     
           
            <asp:SessionParameter Name="idpracownika" SessionField="idpracownika" Type="string" />                                         
           
        </SelectParameters>  
           
    </asp:SqlDataSource>  
    
    <asp:SqlDataSource ID="sql_urlopy_pomoc" ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"  
        ProviderName="System.Data.SqlClient" SelectCommand="select pracownik as idp, opis, pdn, odn from poza_biurem join urlopy on poza_biurem.id = urlopy.id_poza_biurem where pracownik = @idp and aktywny=1"  
        runat="server">   
        <SelectParameters>  
            <asp:SessionParameter Name="idp" SessionField="idp" Type="string" />  
        </SelectParameters>  
        </asp:SqlDataSource>  
           
        <asp:SqlDataSource ID="sql_rok" ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"  
            ProviderName="System.Data.SqlClient" SelectCommand="select distinct kp_rok from kd_urlopy2" SelectCommandType="Text"  
            runat="server"></asp:SqlDataSource>  
      
       
    </form>  
</body>  
</html>

Open in new window

0
Comment
Question by:ASkEPA
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 10

Expert Comment

by:himanshut
ID: 26103023
Post here your Page_Load code as well,

as I need to see how are you checking for Page.IsPosback TRUE OR FALSE.

0
 

Author Comment

by:ASkEPA
ID: 26103027
The Page_load action is empty.
0
 
LVL 3

Expert Comment

by:Andy Green
ID: 26103050
You dont seem to have any default values in the select datasource, so it wont return any data until they are populated with the first postback.
Andy
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 26103066
Just one suggetion
try to declare datasource before grid as shown below
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="raport_urlopy.aspx.vb" Inherits="raport_urlopy" %>  
  
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  
<html xmlns="http://www.w3.org/1999/xhtml">   
<head runat="server">   
    <title>Intranet</title>  
</head>  
<body>  
    <form id="form1" runat="server">   
       
    <div class="gora"><a href="default.aspx"><img src="gfx/intranet2.gif" alt="Intranet" border="0"></a>  
    </div>  
       
    <div class="menu">   
   <!-- #include file="inc-menu.aspx "-->       
         
    </div>  
       
    <div class="srodek">   
       
      
    <asp:ScriptManager ID="ScriptManager1" runat="server">   
    </asp:ScriptManager>  
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">   
        </telerik:RadAjaxManager>  
       
       <div style="text-align:left">   
       <div class="pasek">Raport o urlopach</div>  
       <table border="0">   
       <tr>  
       <td align="right" valign="middle">Rok:</td><td align="left" valign="middle">   
          
         <asp:DropDownList ID="ddl_rok" runat="server" DataSourceID="sql_rok"    
                            DataTextField="kp_rok" DataValueField="kp_rok" Width="258px" AutoPostBack="True">   
         </asp:DropDownList>  
          
       </td>  
       </tr>  
          
       <tr>  
       <td align="right" valign="middle">DziaB:</td><td align="left" valign="middle">   
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sql_dzial"    
                            DataTextField="nazdz" DataValueField="id" Width="258px" AutoPostBack="True"></asp:DropDownList></td>   
       </tr>  
                 
       </table>  
          
    </div>  
          
            <asp:TextBox ID="txt_idp" runat="server" Visible="False"></asp:TextBox>  
          
        <br />  

   <asp:SqlDataSource ID="sql_dzial" runat="server"    
        ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"    
        SelectCommand="proc_wczytaj_dzialy" SelectCommandType="StoredProcedure">   
      
       <SelectParameters>  
        
           <asp:FormParameter DefaultValue="122" FormField="txt_idp" Name="idpracownika"    
               Type="Int32" />  
        
        
       </SelectParameters>         
               
     </asp:SqlDataSource>  
      
    <asp:SqlDataSource ID="sql_urlopy_glowne" runat="server"    
        ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"    
        SelectCommand="proc_pokaz_ilosc_urlopow_w_dziale"    
        SelectCommandType="StoredProcedure">   
           
        <SelectParameters>  
         
            <asp:ControlParameter ControlID="DropDownList1" Name="id_dzial"    
                PropertyName="SelectedValue" Type="Int32" />  
           
             <asp:ControlParameter ControlID="ddl_rok" Name="rok"    
                PropertyName="SelectedValue" Type="Int32" />     
           
            <asp:SessionParameter Name="idpracownika" SessionField="idpracownika" Type="string" />                                         
           
        </SelectParameters>  
           
    </asp:SqlDataSource>  
    
    <asp:SqlDataSource ID="sql_urlopy_pomoc" ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"  
        ProviderName="System.Data.SqlClient" SelectCommand="select pracownik as idp, opis, pdn, odn from poza_biurem join urlopy on poza_biurem.id = urlopy.id_poza_biurem where pracownik = @idp and aktywny=1"  
        runat="server">   
        <SelectParameters>  
            <asp:SessionParameter Name="idp" SessionField="idp" Type="string" />  
        </SelectParameters>  
        </asp:SqlDataSource>  
           
        <asp:SqlDataSource ID="sql_rok" ConnectionString="<%$ ConnectionStrings:Polaczenie-Portal %>"  
            ProviderName="System.Data.SqlClient" SelectCommand="select distinct kp_rok from kd_urlopy2" SelectCommandType="Text"  
            runat="server"></asp:SqlDataSource>       
        
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="sql_urlopy_glowne"    
            GridLines="None" AllowSorting="True" ShowGroupPanel="True" Skin="Hay" allow>  
         
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="idp" DataSourceID="sql_urlopy_glowne">   
                <DetailTables>  
                    <telerik:GridTableView AutoGenerateColumns="false" DataKeyNames="idp" DataSourceID="sql_urlopy_pomoc" Width="100%" runat="server">   
                                             
                        <ParentTableRelation>  
                            <telerik:GridRelationFields DetailKeyField="idp" MasterKeyField="idp" />  
                        </ParentTableRelation>  
                        <Columns>  
                            <telerik:GridBoundColumn SortExpression="opis" HeaderText="Typ" DataField="opis" UniqueName="opis">   
                            </telerik:GridBoundColumn>  
                               
                             <telerik:GridBoundColumn SortExpression="pdn" HeaderText="Od" DataField="pdn" UniqueName="pdn"  DataFormatString="{0:dd-MM-yyyy}">   
                            </telerik:GridBoundColumn>  
                               
                              <telerik:GridBoundColumn SortExpression="odn" HeaderText="Do" DataField="odn" UniqueName="odn"  DataFormatString="{0:dd-MM-yyyy}">   
                            </telerik:GridBoundColumn>  
                        </Columns>  
                                      
                    </telerik:GridTableView>  
                </DetailTables>  
  
<ExpandCollapseColumn Visible="True"></ExpandCollapseColumn>  
  
                <Columns>  
                    <telerik:GridBoundColumn DataField="idp" DataType="System.Int32" HeaderText="idp"  
                        ReadOnly="True" SortExpression="idp" UniqueName="idp" Visible="false">   
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="naz" HeaderText="Nazwisko" SortExpression="naz" UniqueName="naz">   
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="IL_UrlopWymiar" DataType="System.Int16" HeaderText="Wymiar"  
                        SortExpression="IL_UrlopWymiar" UniqueName="IL_UrlopWymiar">   
                    </telerik:GridBoundColumn>  
                      
                    <telerik:GridBoundColumn DataField="KD_IL_UrlopPrzysl" DataType="System.Int16" HeaderText="PrzysBugujcy"  
                        SortExpression="KD_IL_UrlopPrzysl" UniqueName="KD_IL_UrlopPrzysl">   
                    </telerik:GridBoundColumn>  
                       
                     <telerik:GridBoundColumn DataField="IL_UrlopDoWyk" DataType="System.Int16" HeaderText="PozostaBy"  
                        SortExpression="IL_UrlopDoWyk" UniqueName="IL_UrlopDoWyk">   
                    </telerik:GridBoundColumn>  
                </Columns>  
            </MasterTableView>  
            <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True"    
                ReorderColumnsOnClient="True">   
                <Selecting AllowRowSelect="True" />  
            </ClientSettings>  
        </telerik:RadGrid>  
                             
        <br /><br /><br />  
                      
    </div>  
       
       
 
      
       
    </form>  
</body>  
</html>

Open in new window

0
 
LVL 10

Expert Comment

by:himanshut
ID: 26103163
protected void Page_Load(Object sender, Eventargs e)
{
 if (!Page.IsPostBack)
  {
     //SQL query  
     RadGrid1.DataSource = query;
     RadGrid1.DataBind();
  }
}
0
 

Author Comment

by:ASkEPA
ID: 26103179
CarmelinaD - I think that is what is causing the error, but how to solve it?
pratima_mcs - Unfortunately, there is no improvement after changes.
0
 
LVL 3

Expert Comment

by:Andy Green
ID: 26103219
Add default values to your SQL Datasource.
  <SelectParameters>
    <asp:Parameter Name="EmpID" Type="Int32" DefaultValue="0" />
  </SelectParameters>

Use a default value that returns data.  Or you could set the grid empty property to say No data yet please select from dropdowns.
Andy
0
 

Author Comment

by:ASkEPA
ID: 26103274
Himanshut - i try to but there is no result :


 If Not Page.IsPostBack Then

            Dim ds As New SqlDataSource(conn.ConnectionString, "proc_pokaz_ilosc_urlopow_w_dziale")
            ds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
            ds.ID = "sql_urlopy_glowne"
            ds.SelectParameters.Add("id_dzial", DropDownList1.SelectedValue)
            ds.SelectParameters.Add("idpracownika", Session("idpracownika"))
            ds.SelectParameters.Add("rok", ddl_rok.SelectedValue)
            RadGrid1.DataSource = ds
            RadGrid1.DataBind()

End If

Open in new window

0
 

Author Comment

by:ASkEPA
ID: 26103329
Andy - Your solution helped, the problem is that the default data are dependent on user and I need to add them from the code (and then the solution is no longer working). Any idea?

I tried something like this but it's not working :


   If Not Page.IsPostBack Then

            sql_urlopy_glowne.SelectParameters(0).DefaultValue = "0"
            sql_urlopy_glowne.SelectParameters(1).DefaultValue = "2009"
            sql_urlopy_glowne.SelectParameters(2).DefaultValue = Session("idpracownika")

            RadGrid1.DataSourceID = sql_urlopy_glowne.ID
            RadGrid1.DataBind()

        End If

Open in new window

0
 
LVL 3

Expert Comment

by:Andy Green
ID: 26103376
You can only have one data source, If you are now using code behind, remove the radgrids datasource from the delcaration.
This line - DataSourceID="sql_urlopy_glowne"
Andy
0
 

Author Comment

by:ASkEPA
ID: 26103440
Note that all the time I have only 1 data source. It only adds default value to the parameters of the code.
Writing in an earlier post that  "not working" I mean, it behaves like so far (that is working after 1 refresh).
After changing the code result is the same.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            Dim ds As New SqlDataSource(conn.ConnectionString, "proc_pokaz_ilosc_urlopow_w_dziale")
            ds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
            ds.ID = "sql_urlopy_glowne"

            ds.SelectParameters.Add("id_dzial", DropDownList1.SelectedValue)
            ds.SelectParameters.Add("idpracownika", Session("idpracownika"))
            ds.SelectParameters.Add("rok", ddl_rok.SelectedValue)        
            ds.SelectParameters(0).DefaultValue = "0"
            ds.SelectParameters(1).DefaultValue = "2009"
            ds.SelectParameters(2).DefaultValue = Session("idpracownika")

            RadGrid1.DataSourceID = sql_urlopy_glowne.ID
            RadGrid1.DataBind()

        End If

    End Sub

Open in new window

0
 
LVL 3

Expert Comment

by:Andy Green
ID: 26103526
You dont think you need this if you are binding declaratively and the data binding is done automatically if you have  DataSourceID="sql_urlopy_glowne" in the radgrid.
RadGrid1.DataSourceID = sql_urlopy_glowne.ID
RadGrid1.DataBind()

Andy
0
 

Author Comment

by:ASkEPA
ID: 26103559
Yes I know. But the problem is that I can not set the parameter DefaultValue on the aspx page (because it is different for different users).
I have to do this on the code in Page Load event and then this does not solve my problem (because the data are still loaded after 1 refresh.)
0
 
LVL 3

Accepted Solution

by:
Andy Green earned 1500 total points
ID: 26103594
You can keep the setting of the parameters, just remove the databinding bits, and see how that goes. The other approach is to do it all in the code behind. There are several examples on the Telerik site.
ANdy
0
 
LVL 10

Expert Comment

by:himanshut
ID: 26108831
Do you mean by Refreshing the page, That any Event Click?

Coz I had the same issue and I tried few things with PostBack, so let me know if it stop displaying the data once any button is clicked or you do pagination
0
 

Author Closing Comment

by:ASkEPA
ID: 31668898
.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question