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

GridHyperLinkColumn Value dissappeared when RadGrid is rebind

3 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
illumination
Top achievements
Rank 2
illumination asked on 10 Sep 2009, 07:30 PM
I have a Radgrid that the first column is created with:
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" Width="100%" 
            AllowSorting="True" GridLines="None" Skin="Web20" OnNeedDataSource="RadGrid1_NeedDataSource" 
             OnSortCommand="RadGrid1_SortCommand" OnItemCreated="RadGrid1_ItemCreated" AllowPaging="true"   
             AutoGenerateColumns="False" > 
<MasterTableView > 
<Columns> 
                   <telerik:GridHyperLinkColumn DataNavigateUrlFields="EMPLOYEEID" DataNavigateUrlFormatString="~/Search.aspx?EMPLOYEEID={0}" 
                        DataTextField="EMPLOYEEID" HeaderText="ID" AllowFiltering="true" FilterControlWidth="35px" UniqueName="EMPLOYEEID">  
                        <HeaderStyle ForeColor="White" Font-Names="Arial Narrow" Font-Size="Small" />                  
                        <ItemStyle Font-Names="Arial Narrow" Font-Size="Small" Font-Bold="True" Font-Underline="True" /> 
                    </telerik:GridHyperLinkColumn> 
                    <telerik:GridBoundColumn DataField="IDENTIFIER" HeaderText="IDENTIFIER" SortExpression="IDENTIFIER" 
                        UniqueName="IDENTIFIER">  
                    </telerik:GridBoundColumn> 
.....  
</Columns> 
<PagerStyle Mode="NumericPages" PageButtonCount="10" /> 
</MasterTableView> 
The problem I am having is:
Radgrid1 is generated on page load and it is working correctly... appeared with the first column with hyperlink ability. Then I click other grid control such as next page or filtering... then the ID dissappeared. so the first column only showing me dashes (-).
Can anybody help me on how to fix this problem?
Thank you.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Sep 2009, 08:18 AM
Hi illumination,

According to posted code RadGrid is declared on page however you stated that "Radgrid1 is generated on page load" -  can you clarify this confusion?

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
illumination
Top achievements
Rank 2
answered on 11 Sep 2009, 02:13 PM
Vlad,
Thank you for the quick reply. the grid is loaded after the user click one of the radiobutton option and then click search button. sorry for the confusion.
0
Princy
Top achievements
Rank 2
answered on 12 Sep 2009, 08:04 AM
Hi illumination,

When you perform Search operation the Grid is populated in the button's click event. After that when you perform any operation that causes a PostBack the Grid will be empty since its DataSource is not set in the succeeding PostBacks.

   So in order to retain the Search result while Paging/Sorting etc store the filtered result to a ViewState in the button click event and then in the NeedDataSource event populate the Grid again from the ViewState.  NeedDataSource  event will be fired each and every time a Grid operation is performed. Here is a Sample code:

ASPX:
 
   <telerik:RadGrid ID="RadGrid1" runat="server"  AllowPaging="true" PageSize="5"   ShowGroupPanel="true" OnNeedDataSource="RadGrid1_NeedDataSource"
            <MasterTableView CommandItemDisplay="Top"
            </MasterTableView> 
            <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true" > 
            </ClientSettings> 
        </telerik:RadGrid> 
 
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Filter" /> 


CS:
 
  protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        if (ViewState["GridData"] != null
        { 
            RadGrid1.DataSource = ViewState["GridData"]; 
        } 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
         string connectionstring = "Data Source=MyData; Initial Catalog=NorthWind;User ID=***; Password=*****"
         SqlConnection conn = new SqlConnection(connectionstring); 
         SqlCommand cmd = new SqlCommand(); 
             conn.Open(); 
            SqlDataAdapter adp = new SqlDataAdapter("select * from  Products", conn); 
            DataTable dt = new DataTable(); 
            adp.Fill(dt); 
            ViewState["GridData"] = dt; 
 
            if (ViewState["GridData"] != null
            { 
                RadGrid1.DataSource = ViewState["GridData"]; 
            } 
            RadGrid1.DataBind(); 
            conn.Close();  
    } 

Thanks
Princy

Tags
Grid
Asked by
illumination
Top achievements
Rank 2
Answers by
Vlad
Telerik team
illumination
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or