This is a migrated thread and some comments may be shown as answers.
Radgrid header
11 Answers 32 Views
This is a migrated thread and some comments may be shown as answers.
Rajeswari
Top achievements
Rank 1
Rajeswari asked on 10 Nov 2014, 02:49 PM
Hi
I have a question regarding radgrid header. I want to make 4 headers  in the grid redirect to a  different page and display as a link. How can i capture the click event of the header as i have to  loop through the radgrid and get the values of that column (header clicked column) to update the table.

Thanks,
Rajeswari Raman

11 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Nov 2014, 04:58 PM
Hello,

Please try with the below code snippet.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.SortCommandName)
    {
        e.Canceled = true;
        Response.Redirect("Default.aspx?HeaderName=" + e.CommandArgument);
    }
}
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"      AllowMultiRowSelection="true" OnItemCommand="RadGrid1_ItemCommand" AllowSorting="true">
    <MasterTableView AutoGenerateColumns="False">
        <Columns>
            <telerik:GridClientSelectColumn></telerik:GridClientSelectColumn>
            <telerik:GridBoundColumn DataField="Id" HeaderText="Id" UniqueName="Id">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
  
</telerik:RadGrid>

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Rajeswari
Top achievements
Rank 1
answered on 10 Nov 2014, 08:22 PM
Hi
Thanks for your reply. How can i find out which cloumn header  is clicked. I have total six columns in the grid . I want to allow sorting in the first two columns only, Other 4 columns header  i want to display as a link and if i click on those column headers i want redirect to a different page . Before redirecting i want to capture the values of the column clicked  in the grid and save to a table . I am having autogenerate columns set to true in the grid.
Thanks for your help
Rajeswari Raman
0
Rajeswari
Top achievements
Rank 1
answered on 11 Nov 2014, 01:57 PM
Hi
I have the grid with autogeneratecolumns set to true. First two columns i want to  allow sorting and rest of the column headers has to be a link , onclick of the header links it has redirect to a different page . How do i capture the on click event of the haeaders as i have to loop through the radgrid columns and get the  values of that clicked column  to be saved toa table . Thanks for your help
Rajeswari Raman
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Nov 2014, 09:06 AM
Hi,

Below code will return column header name in my above given code snippet.

e.CommandArgument


Thanks,
Jayesh Goyani
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Nov 2014, 09:10 AM
Hi,

Please try with below code snippet.

if (e.CommandName == RadGrid.SortCommandName)
{
    if (e.CommandArgument == "YouColumnName3" || e.CommandArgument == "YouColumnName4") // Please change column name here if you want to redirect to other page on click of that header text
    {
        e.Canceled = true;
        Response.Redirect("Default.aspx?HeaderName=" + e.CommandArgument);
    }
}

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Rajeswari
Top achievements
Rank 1
answered on 12 Nov 2014, 07:05 PM
Thanks for your reply. That resolved the problem  I want to change the default page size of the radgrid with page size 50 and 100 only .i added the following in  radgrid itemCreated event
Dim myPageSizeCombo As RadComboBox = e.Item.FindControl("PageSizeComboBox")
Dim myItem As RadComboBoxItem
myPageSizeCombo.Items.Clear()
myItem = New RadComboBoxItem("50", "50")
myPageSizeCombo.Items.Add(myItem)
myItem.Attributes.Add("ownerTableViewId", grdgroup.MasterTableView.ClientID)
myItem = New RadComboBoxItem("100", "100")
myPageSizeCombo.Items.Add(myItem)
myItem.Attributes.Add("ownerTableViewId", grdgroup.MasterTableView.ClientID)
  I always get  object reference error  the following code (grdgroup pagsize.tostring showing as 10which is default in debug)     
  myPageSizeCombo.FindItemByText(grdgroup.PageSize.ToString()).Selected = True

Thanks,
Rajeswari Raman
     

0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Nov 2014, 05:42 PM
Hi,

Please try with the below code snippet.

<PagerStyle   PageSizes="5,10,25,50,100,250" />

OR

Customizing items of RadGrid page size combo based on total records


Let me know if any concern.

Thanks,
Jayesh Goyani
0
Rajeswari
Top achievements
Rank 1
answered on 17 Nov 2014, 03:12 PM
Hi,
I want to show pagersize 50, 100 only as default . I dont want based on record count . I always get  null refrence error on the following line  
myPageSizeCombo.FindItemByValue(grdgroup.PageSize.ToString()).Selected = True
I added the following code in item databound function.
  If TypeOf (e.Item) Is GridPagerItem Then

Dim myPageSizeCombo As RadComboBox = e.Item.FindControl("PageSizeComboBox")
Dim myItem As RadComboBoxItem
myPageSizeCombo.Items.Clear()
myPageSizeCombo.AutoPostBack = True
myPageSizeCombo.Items.Add(New RadComboBoxItem("50"))
myPageSizeCombo.FindItemByText("50").Attributes.Add("ownerTableViewId", grdgroup.MasterTableView.ClientID)
'myPageSizeCombo.FindItemByText(grdgroup.PageSize.ToString()).Selected = True
myPageSizeCombo.Items.Add(New RadComboBoxItem("100"))
myPageSizeCombo.FindItemByText("100").Attributes.Add("ownerTableViewId", grdgroup.MasterTableView.ClientID)
myPageSizeCombo.FindItemByValue(grdgroup.PageSize.ToString()).Selected = True
End If
Following is my aspx code
<PagerStyle Mode="NextPrevAndNumeric" BorderStyle="None"
AlwaysVisible="true" PageSizeControlType="RadComboBox" ></PagerStyle>
Thanks,
Rajeswari Raman
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Nov 2014, 05:44 PM
Hi,

Please try with the below code snippet.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        GridPagerItem pagerItem = (GridPagerItem)e.Item;
        RadComboBox pageSizeCombo = (RadComboBox)pagerItem.FindControl("PageSizeComboBox");
        pageSizeCombo.Items.Clear();
        
 
         
            RadComboBoxItem item = new RadComboBoxItem();
            item = new RadComboBoxItem("50","50");
            item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
            pageSizeCombo.Items.Add(item);
 
            item = new RadComboBoxItem("100", "100");
            item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
            pageSizeCombo.Items.Add(item);
         
         
        pageSizeCombo.FindItemByValue("50").Selected = true;
 
    }
 
}


Let me know if any concern.

Thanks,
Jayesh Goyani
0
Rajeswari
Top achievements
Rank 1
answered on 17 Nov 2014, 06:58 PM
Hi ,
I modified the code as you posted . Now I am not getting null refrence error. But when the grdloaded first time eventhough there were 65 items it was showing as 0 items in 1 page in the bottom of the grid . The pagesize combo was showing 50,100. When i change  pagesize to 100 in the combo,   it was showing all the page index from 1 to seven and the display was 65 items in 7 pages . it was always defaulting to  default pagesize and page indexes. On the aspx side i have Allowcustompaging set to true .
Thanks
Rajeswari Raman
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Nov 2014, 05:19 AM
Hi,

My apologies for the inconvenience.

Could you please provide your code so based on that I will create demo?

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Rajeswari
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Rajeswari
Top achievements
Rank 1
Share this question
or