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

[Solved] retrieve selected value when column is changed to template

1 Answer 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 15 Sep 2009, 09:00 PM
Hi guys

I am retrieving a value from a grid bound column in a selected row like this:

Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged  
 
        Dim strName, strVintage As String 
          
        For Each item As GridDataItem In RadGrid1.SelectedItems  
             
            strName = item("Name").Text  
            strVintage = item("Vintage").Text  
            ' do stuff here   
        Next  
End Sub 

The problem arises when I want to tootip the items in the "Name" column.  As part of this process I have to convert the Name column
to a template, but as soon as I do this, the item("Name").Text value retrieved is an empty string.

How can I modify the approach to retrieve the value when the column is converted to a template field?

Sorry if this is very obvious because I have not found a way of doing it! 

Thanks
Clive

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Sep 2009, 05:18 AM
Hello Clive,

I suppose you are using a Label or a Literal Control inorder to bind data to your Template column. If so, then you would have to access the control first to retrieve its text. Check out the code below for the same:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
      if (e.Item is GridDataItem) 
       { 
            GridDataItem item = (GridDataItem)e.Item; 
            Label lbl = (Label)item.FindControl("LabelControlID"); 
       } 
    } 

Hope this helps..
Princy.
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or