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

RowIndex ASP.NET code

4 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 05 Feb 2009, 09:16 AM
What is the equivalent of the following code which does exactly what i want with the standard GridView?
<div runat="server" ID='<%# String.Concat("div", CType(Container, GridViewRow).RowIndex %>'
' content here 
</div> 

However it's a bit confusing when you work with the RadGrid.

Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 05 Feb 2009, 11:06 AM
Hello,

You can try out the following code while using RadGrid where GridDataItem represents a GridViewRow and ItemIndex represents represents RowIndex.
<div runat="server" ID='<%# String.Concat("div", CType(Container, Telerik.Web.UI.GridDataItem).ItemIndex %>'>  
' content here  
</div> 

Thanks
Princy.
0
El
Top achievements
Rank 1
answered on 05 Feb 2009, 11:10 AM
Hi Princy,

You seem the only one who helps me here. Thank you very much for that.

Btw, when i try to use the suggested code i am getting a parse error:

The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:Button runat="server" id="Button1" />
________________________________________
Line 188:            
Line 189:
Line 190:<div id='<%# String.Concat("div", CType(Container, Telerik.Web.UI.GridDataItem).ItemIndex %>' runat="server" class="container hide">

Any idea ? Thanks once again.







0
Daniel
Telerik team
answered on 05 Feb 2009, 11:14 AM
Hello El,

I recommend you visit the following links:
RadControls for ASP.NET AJAX vs the default Microsoft web controls in Visual Studio
RadGrid Data items

Regarding your question:
GridViewRow = GridItem
RowIndex = ItemIndex

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 1
answered on 06 Feb 2009, 07:51 AM
Hi El,

You can try setting the Id of the generic control from the code behind as shown in the example below. Here, I'm creating a TemplateColumn with a Label in its ItemTemplate. In the code behind, I access the label and set the text of the label to a string, which contains the generic control with the id set to index of the grid row:
aspx:
<telerik:RadGrid ID="RadGrid2" runat="server"  OnItemDataBound="RadGrid2_ItemDataBound"
       <MasterTableView> 
        <Columns> 
         <telerik:GridTemplateColumn UniqueName="Template"
           <ItemTemplate> 
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
      
           </ItemTemplate> 
         </telerik:GridTemplateColumn> 
        </Columns> 
       </MasterTableView> 
 </telerik:RadGrid> 

cs:
 
 protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)   
          {  
               GridDataItem dataItem = (GridDataItem)e.Item;  
               Label label = (Label)dataItem["TemplateColumn"].FindControl("Label2");  
               string div = String.Empty;  
  
               div = "<div id=div" + dataItem.ItemIndex.ToString() + " runat='server' style='background-color:Red' class='container hide'>content here </div>";  
                
               label.Text = div;  
          }  
    }  

Hope this helps...
Princy.
Tags
Grid
Asked by
El
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
El
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or