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

Add a numbered column to RadGrid

4 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CBARS
Top achievements
Rank 2
CBARS asked on 25 Sep 2008, 05:36 AM
Hi

I want to add a column to the RadGrid that contains a row counter. This has no data effect, and will only be used for reference and also as a drill-down button.

Is there an easier way than intercepting the ItemDataBound event and adding a column to each row?

4 Answers, 1 is accepted

Sort by
0
CBARS
Top achievements
Rank 2
answered on 25 Sep 2008, 06:00 AM
What I've done is :

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
      int i = 0
      foreach (GridDataItem item in RadGrid1.Items) 
      { 
          i++; 
          item.Cells[2].Text = i.ToString(); 
      } 
 

I have made my first column a hyperlink,

<telerik:GridHyperLinkColumn DataNavigateUrlFormatString="DrillDownPage.aspx?userid={0}"  
                             DataNavigateUrlFields="Userid" HeaderText="#"
</telerik:GridHyperLinkColumn> 

After the text is changed in the ItemDataBound event, the text in the column is no longer a hyperlink. Am I doing something wrong?





0
Maria Ilieva
Telerik team
answered on 29 Sep 2008, 06:32 AM
Hello cbars,

 Please review the following help topic which will help you to acheive the required functionality.

Greetings,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
CBARS
Top achievements
Rank 2
answered on 29 Sep 2008, 12:04 PM
Hi Maria...

Thanks for the article... Looks like it will help. That approach doesn't work though when you have a dynamically generated dataset passed as datasource to the RadGrid, as well as having a detail table. Here's my code :

<telerik:RadGrid Settings="Here"
   <Columns> 
      <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Row number"
         <ItemTemplate> 
            <asp:HyperLink id="hplDrillDown" runat="server" Text="" NavigateURL="" target="_blank" /> 
         </ItemTemplate> 
      </telerik:GridTemplateColumn> 
   </Columns> 
</telerik:RadGrid> 

and the code-behind :

if (e.Item is GridDataInsertItem) 
      HyperLink hpl = e.Item.FindControl("hplDrillDown") as HyperLink; 
      hpl.Text = (e.Item.ItemIndex + 1).ToString(); 
      hpl.NavigateUrl = string.Format("~/Destination.aspx?userid={0}", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"].ToString());                




The grid shows, but whenever I try to expand one of the master table items, the RadGrid wants to fill the hplDrillDown on each detail row, which it doesn't find.

How can I check whether a row is a child of the master table view?
0
Accepted
Maria Ilieva
Telerik team
answered on 30 Sep 2008, 12:06 PM
Hi cbars,

Please refer to the following forum post which shows how to set this functionality for detail table.

All the best,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
CBARS
Top achievements
Rank 2
Answers by
CBARS
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or