Trouble finding control reference in grid

3 posts, 1 answers
  1. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 25 May 2010 Link to this post

    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. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 May 2010 Link to this post

    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.



  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 26 May 2010 Link to this post

    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
Back to Top