Checkbox In GridTemplateColumn

2 posts, 0 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 22 May 2015 Link to this post

    I have a Checkbox in a gridtemplatecolumn. When checked I would like it to auto post back. Everything seems to work, however I cannot get the DataKeyValue.

     

    <telerik:RadGrid ID="rgd_OrdersNew" runat="server" DataSourceID="sds_ETP_OrdersShipped"
                                            AllowSorting="True" Width="800px">
                                            <MasterTableView AutoGenerateColumns="False" DataSourceID="sds_ETP_OrdersShipped"
                                                DataKeyNames="IDOrder, InvoiceNumber" ClientDataKeyNames="IDOrder, InvoiceNumber"
                                                HeaderStyle-Wrap="False" HeaderStyle-HorizontalAlign="Center">
                                                <Columns>
                                                    <telerik:GridTemplateColumn DefaultInsertValue="" HeaderText=" " UniqueName="TemplateColumn"
                                                        ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10px" ItemStyle-CssClass="radgrid_count"
                                                        FooterStyle-CssClass="radgrid_count">
                                                        <ItemTemplate>
                                                            <%# Container.ItemIndex+1 %>
                                                        </ItemTemplate>
                                                        <FooterStyle CssClass="radgrid_count"></FooterStyle>
                                                        <ItemStyle HorizontalAlign="Center" CssClass="radgrid_count" Width="10px"></ItemStyle>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridBoundColumn DataField="InvoiceNumber" DataType="System.Int32" FilterControlAltText="Filter InvoiceNumber column"
                                                        HeaderText="Invoice" SortExpression="InvoiceNumber" UniqueName="InvoiceNumber"
                                                        ItemStyle-HorizontalAlign="Center" DataFormatString="ETP-{0}" ItemStyle-ForeColor="#597791"
                                                        ItemStyle-Width="60px" ItemStyle-Wrap="False">
                                                        <ItemStyle HorizontalAlign="Center" Wrap="False" ForeColor="#597791" Width="60px">
                                                        </ItemStyle>
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="IDOrder" DataType="System.Int32" FilterControlAltText="Filter IDOrder column"
                                                        HeaderText="Order ID" SortExpression="IDOrder" UniqueName="IDOrder" ItemStyle-HorizontalAlign="Center"
                                                        Visible="True">
                                                        <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="OrderStatus" FilterControlAltText="Filter OrderStatus column"
                                                        HeaderText="Status" ReadOnly="True" SortExpression="OrderStatus" UniqueName="OrderStatus"
                                                        Visible="False">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="TrackingCode" FilterControlAltText="Filter TrackingCode column"
                                                        HeaderText="Tracking Code" ReadOnly="True" SortExpression="TrackingCode" UniqueName="TrackingCode"
                                                        Visible="True">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="ShippingMethod" FilterControlAltText="Filter ShippingMethod column"
                                                        HeaderText="Shipping" ReadOnly="True" SortExpression="ShippingMethod" UniqueName="ShippingMethod"
                                                        Visible="True" ItemStyle-Wrap="False">
                                                        <ItemStyle Wrap="False" Width="100px"></ItemStyle>
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="IDCustomer" DataType="System.Int32" FilterControlAltText="Filter IDCustomer column"
                                                        HeaderText="Customer ID" SortExpression="IDCustomer" UniqueName="IDCustomer"
                                                        ItemStyle-HorizontalAlign="Center" Visible="False">
                                                        <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="DateOrder" DataType="System.DateTime" FilterControlAltText="Filter DateOrder column"
                                                        HeaderText="Order Date" SortExpression="DateOrder" UniqueName="DateOrder" ItemStyle-HorizontalAlign="Right">
                                                        <ItemStyle HorizontalAlign="Right" Wrap="False"></ItemStyle>
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="OrderLastName" FilterControlAltText="Filter OrderLastName column"
                                                        HeaderText="Last Name" SortExpression="OrderLastName" UniqueName="OrderLastName">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="OrderFirstName" FilterControlAltText="Filter OrderFirstName column"
                                                        HeaderText="First Name" SortExpression="OrderFirstName" UniqueName="OrderFirstName">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridHyperLinkColumn DataNavigateUrlFields="TrackingCode" HeaderText=" "
                                                        DataNavigateUrlFormatString="https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=[{0}]"
                                                        Text="Track" UniqueName="TrackingCode" AllowFiltering="False" ItemStyle-HorizontalAlign="Center"
                                                        Target="BLANK">
                                                        <ItemStyle Width="75px" CssClass="tbltdbutton" />
                                                    </telerik:GridHyperLinkColumn>
                                                    <telerik:GridTemplateColumn>
                                                        <ItemTemplate>
                                                            <asp:CheckBox ID="cbx_Deliverd" Checked='<%# Convert.ToBoolean(Eval("Delivered")) %>'
                                                                AutoPostBack="true" OnCheckedChanged="cbx_Deliverd_CheckedChanged" runat="server" />
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                </Columns>
                                            </MasterTableView>
                                            <ClientSettings EnablePostBackOnRowClick="true" AllowColumnsReorder="true" ReorderColumnsOnClient="true"
                                                EnableRowHoverStyle="true">
                                                <Selecting AllowRowSelect="true" />
                                            </ClientSettings>
                                        </telerik:RadGrid>

     

     

    Protected Sub cbx_Deliverd_CheckedChanged(sender As Object, e As EventArgs)
     
        Dim cbx_Deliverd As CheckBox = DirectCast(sender, CheckBox)
        Dim item As GridDataItem = DirectCast(cbx_Deliverd.NamingContainer, GridDataItem)
        Dim Deliverd As CheckBox = DirectCast(cbx_Deliverd.FindControl("cbx_Deliverd"), CheckBox)
        Dim IDOder As String = item.GetDataKeyValue("IDOder").ToString()
     
        If Deliverd.Checked Then
     
            Dim sql As String
            Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("ETP_OPS_ConnectionString").ConnectionString()
            sql = "UPDATE Orders_Shipping SET Delivered = @Delivered WHERE IDOder = @IDOder"
            Dim connection As New SqlConnection(strConnString)
            Dim command As New SqlCommand(sql, connection)
     
            command.Parameters.Add("@IDOder", SqlDbType.Int).Value = IDOder
            command.Parameters.Add("@Delivered", SqlDbType.Int).Value = 1
            command.Connection.Open()
            command.ExecuteNonQuery()
            command.Connection.Close()
     
        End If
     
    End Sub

     

     As always, any help much appreciated.

     

     

     

  2. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 22 May 2015 in reply to Allan Link to this post

    Please disregard.

     Embarassingly, I misspelled the datakeyvalue item name as IDOder and is should have been IDOrder

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top