Select not working

1 posts, 0 answers
  1. Suzan
    Suzan avatar
    17 posts
    Member since:
    Feb 2011

    Posted 05 Sep 2017 Link to this post

    Hi for some reason my select row code does not work

    My grid definition is below

     

    <telerik:radgrid runat="server" id="RadGridAppointmentList" showfooter="false" width="100%" enableajax="true" showstatusbar="true" allowautomaticinserts="false"
    onitemcommand="RadGridAppointmentList_ItemCommand" onitemcreated="RadGridAppointmentList_ItemCreated" AllowMultiRowSelection="false"
    allowaddingrecords="false" autogeneratecolumns="false" allowsorting="false" allowpagesizeselection="False" onitemdatabound="OnItemDataBoundHandler" allowautomaticupdates="false"
    allowpaging="True" skin="Bootstrap" pagesize="25" onneeddatasource="RadGridAppointmentList_NeedDataSource" onprerender="RadGridAppointmentList_PreRender" cssclass="table table-striped">
    <MasterTableView AutoGenerateColumns="false" DataKeyNames="ref" TableLayout="Auto" EditMode="EditForms" CommandItemDisplay="None" >
    <Columns>
    <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false" HeaderText="Select" ItemStyle-Width="45" HeaderStyle-Width="45" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true">
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" OnCheckedChanged="CheckUncheckItem" AutoPostBack="True"
    runat="server"></asp:CheckBox>
    </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridButtonColumn CommandName="Edit" UniqueName="EditColumn" Text="Edit" ItemStyle-Width="45px" HeaderText="Edit" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true">
    </telerik:GridButtonColumn>
    <telerik:GridBoundColumn DataField="ref" runat="server" Display="false" ItemStyle-Width="1" ItemStyle-ForeColor="White" UniqueName="ref">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="studentname" DataField="" HeaderText="Name" runat="server" ItemStyle-Wrap="true" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true"
    ItemStyle-Width="100" ReadOnly="true">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="Id_No" DataField="id_no" HeaderText="Student" runat="server" ItemStyle-Width="30px"
    Display="false" ReadOnly="true">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="bookeddate" DataField="bookeddate" HeaderText="Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" runat="server"
    ItemStyle-Width="100" Display="false">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="selectedtime" HeaderText="Time" runat="server" ItemStyle-Width="80" Display ="false">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="appointmentdate" HeaderText="Date and Time" runat="server" ItemStyle-Width="110px" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="staff_id" HeaderText="Name" runat="server" ItemStyle-Width="100px" Display="false">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="staff_name" DataField="" HeaderText="Staff Name" runat="server" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" ItemStyle-Width="100" Display="true">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="status" HeaderText="Status" HeaderStyle-BackColor="#428bca" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true" UniqueName="status"
    runat="server" ItemStyle-Width="130px">
    </telerik:GridBoundColumn>
    </Columns>
    <EditFormSettings EditFormType="Template">
    <EditColumn UniqueName="EditColumn">
    </EditColumn>
    <FormTemplate>
    <table style="width: 100%" border="0" >
    <tr style="border:solid">
    <td colspan="2"><b>Edit Appointment</b><br /></td>
    </tr>
    <tr>
    <td colspan="2">
    <br />
    Select Status<br />
    <telerik:RadComboBox ID="RadComboBoxStatus" runat="server" EmptyMessage="Select Status" CausesValidation="False"
    HighlightTemplatedItems="true" Height="100px" Width="450px" DropDownWidth="450px" EnableAutomaticLoadOnDemand="False" AutoPostBack="true"
    AppendDataBoundItems="true" Visible="true" CssClass="ComboBox" OnSelectedIndexChanged="RadComboBoxStatus_SelectedIndexChanged">
    <Items>
    <telerik:RadComboBoxItem value="absent" text="absent" />
    <telerik:RadComboBoxItem value="present" text="present" />
    <telerik:RadComboBoxItem value="session_cancelled" text="session_cancelled" />
    </Items>
    </telerik:RadComboBox>
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:Button ID="btnSave" CausesValidation="False" Text="Save"
    runat="server" AutoPostBack="True" CommandName="Update"></asp:Button>&nbsp;
    </td>
    </tr>
    </FormTemplate>
    </EditFormSettings>
    </MasterTableView>
    <ClientSettings EnablePostBackOnRowClick="True">
    <Selecting AllowRowSelect="true"></Selecting>
    </ClientSettings>
    <SelectedItemStyle BackColor="Gray" BorderColor="Blue" BorderStyle="Dashed" BorderWidth="1px" />
    </telerik:radgrid>

     

    This is my select code

    Protected Sub CheckUncheckItem(sender As Object, e As EventArgs)
    Dim selectedItems As ArrayList
    TryCast(TryCast(sender, CheckBox).NamingContainer, GridItem).Selected = TryCast(sender, CheckBox).Checked
    Dim CheckBox1 As CheckBox = DirectCast(sender, CheckBox)
    Dim item As GridDataItem = DirectCast(CheckBox1.NamingContainer, GridDataItem)
    If CheckBox1.Checked Then
    Dim refno As String = item.GetDataKeyValue("ref").ToString()
    selectedItems.Add(refno)
    Session("selectedItems") = selectedItems
    Else
    Dim refno As String = item.GetDataKeyValue("ref").ToString()
    selectedItems.Remove(refno)
    Session("selectedItems") = selectedItems
    End If

    End Sub

    The line selectedItems.Add(refno) is failing

    Error is Error Message: Object reference not set to an instance of an object.

    Does the ref column need to be visible to make it work?

     

     

     

Back to Top