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

Trouble finding control reference in grid

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 1
Andy Green asked on 25 May 2010, 02:59 PM
Hi

Sorry to ask such a basic question, but I just cant get it.

I think this is simple, I have a checkbox in a row, and all I want is the ID of the row when the checkbox is check or unchecked.

This is my markup:
                <telerik:GridTemplateColumn HeaderText="Arrival" SortExpression="TimeArrival" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center" AllowFiltering="false">  
                    <ItemTemplate> 
                        <asp:CheckBox ID="chkTimeArrival" runat="server" AutoPostBack="True" OnCheckedChanged="chkTimeArrival_CheckedChanged"/>  
                        <asp:Label ID="lblTimeArrival" runat="server" Text='<%# Bind("TimeArrival") %>'></asp:Label>    
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 

This is my code stub:
    Protected Sub chkTimeArrival_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)  
 
    End Sub 

In the function chkTimeArrival_CheckedChanged how do I get the ID of the row.

I have the id in a hidden row:

 

<telerik:GridBoundColumn DataField="AppID" UniqueName="AppID" Visible="false"></telerik:GridBoundColumn>

 


And in the datakeynames

<

 

MasterTableView DataKeyNames="AppID">

Andy

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 May 2010, 06:22 AM
Hello Andy,

In order to get the Id of the row , access the row using NamingContainer property of CheckBox . And then use the function GetDataKeyValue, which returns the dataKeyValue, associated with the dataItem.

VB.Net
  
  Protected Sub CheckBox1_CheckedChanged(ByVal sender As ObjectByVal e As EventArgs) 
        Dim chk1 As CheckBox = DirectCast(sender, CheckBox) 
        Dim item As GridDataItem = DirectCast(chk1.NamingContainer, GridDataItem) 
        Dim id As String = item.GetDataKeyValue("AppID").ToString() 
   End Sub 
 

Regards,
Princy.



0
Andy Green
Top achievements
Rank 1
answered on 26 May 2010, 09:45 AM
Thank you

One small thing that is not a Telerik problem but if you can offer any help it would be appreciated.

The grid is updated with a timer every 60 second, when I tick the checkbox the serverside event chkTimeArrival_CheckedChanged fires and I run my proc all ok, but when the timer tick next fires the chkTimeArrival_CheckedChanged event fires again but only once.


Andy
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Andy Green
Top achievements
Rank 1
Share this question
or