This is a migrated thread and some comments may be shown as answers.
RadGrid Grid Column If GridColumn is empty
1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 22 May 2015, 07:08 AM

I would like to execute a stored procedure for each record where the last name column is empty but I can't seem to get this to work.

 

Grid Code

 

<telerik:RadGrid ID="rgd_OrdersNew" runat="server" CellSpacing="0" DataSourceID="sds_ETP_OrdersNew"
                                    GridLines="None" AllowSorting="True">
                                    <MasterTableView AutoGenerateColumns="False" DataSourceID="sds_ETP_OrdersNew" DataKeyNames="IDOrder, InvoiceNumber, OrderLastName"
                                        ClientDataKeyNames="IDOrder, InvoiceNumber, OrderLastName" HeaderStyle-Wrap="False" HeaderStyle-HorizontalAlign="Center">
                                        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                                        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                                        </ExpandCollapseColumn>
                                        <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>
                                            </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">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="IDOrder" DataType="System.Int32" FilterControlAltText="Filter IDOrder column"
                                                HeaderText="Order ID" SortExpression="IDOrder" UniqueName="IDOrder" ItemStyle-HorizontalAlign="Center"
                                                Visible="False">
                                            </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="ShippingMethod" FilterControlAltText="Filter ShippingMethod column"
                                                HeaderText="Shipping" ReadOnly="True" SortExpression="ShippingMethod" UniqueName="ShippingMethod"
                                                Visible="True" ItemStyle-Wrap="False">
                                            </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">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="DateOrder" DataType="System.DateTime" FilterControlAltText="Filter DateOrder column"
                                                HeaderText="Order Date" SortExpression="DateOrder" UniqueName="DateOrder" ItemStyle-HorizontalAlign="Right"
                                                DataFormatString="<nobr>{0}</nobr>">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="OrderCompany" FilterControlAltText="Filter OrderCompany column"
                                                HeaderText="Company" SortExpression="OrderCompany" UniqueName="OrderCompany">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="OrderLastName" FilterControlAltText="Filter OrderLastName column"
                                                HeaderText="Last Name" SortExpression="OrderLastName" UniqueName="OrderLastName"
                                                ItemStyle-Width="100px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="OrderFirstName" FilterControlAltText="Filter OrderFirstName column"
                                                HeaderText="First Name" SortExpression="OrderFirstName" UniqueName="OrderFirstName"
                                                ItemStyle-Width="100px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="OrderStep" FilterControlAltText="Filter OrderStep column"
                                                HeaderText="Step" SortExpression="OrderStep" UniqueName="OrderStep" ItemStyle-HorizontalAlign="Center">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="OrderAmount" DataType="System.Decimal" FilterControlAltText="Filter OrderAmount column"
                                                HeaderText="Order Total" SortExpression="OrderAmount" UniqueName="OrderAmount"
                                                DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="PayMethodType" FilterControlAltText="Filter PayMethod column"
                                                HeaderText="Pay Method" SortExpression="PayMethodType" UniqueName="PayMethodType"
                                                ItemStyle-HorizontalAlign="Center" ItemStyle-Wrap="False">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="CardType" FilterControlAltText="Filter CardType column"
                                                HeaderText="CardType" SortExpression="CardType" UniqueName="CardType" ItemStyle-HorizontalAlign="Center"
                                                Visible="False">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Items" DataType="System.Int32" FilterControlAltText="Filter Items column"
                                                HeaderText="Items" SortExpression="Items" UniqueName="Items" ItemStyle-HorizontalAlign="Center">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Sheets" DataType="System.Int32" FilterControlAltText="Filter Sheets column"
                                                HeaderText="Sheets" SortExpression="Sheets" UniqueName="Sheets" ItemStyle-HorizontalAlign="Center">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="PastOrdersCount" DataType="System.Int32" FilterControlAltText="Filter PastOrdersCount column"
                                                HeaderText="Orders" SortExpression="PastOrdersCount" UniqueName="PastOrdersCount"
                                                ItemStyle-HorizontalAlign="Center" ItemStyle-BackColor="#CCFFCC">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <ClientSettings>
                                        <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
                                        <Selecting AllowRowSelect="True"></Selecting>
                                        <ClientEvents OnRowDblClick="OrderDetails_OnRowDblClick" />
                                    </ClientSettings>
                                    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                                    <FilterMenu EnableImageSprites="False">
                                    </FilterMenu>
                                </telerik:RadGrid>

 

 

Code Behind

 

Protected Sub rgd_OrdersNew_DataBound(sender As Object, e As System.EventArgs) Handles rgd_OrdersNew.DataBound
    For Each gridDataItem As GridDataItem In rgd_OrdersNew.Items
 
        Dim OrderLastName As String = gridDataItem("OrderLastName").Text
        If OrderLastName Is Nothing OrElse OrderLastName = String.Empty Then
 
            Dim IDOrder As String = gridDataItem.GetDataKeyValue("IDOrder").ToString()
 
            Dim connectionString As String = DirectCast(ConfigurationManager.ConnectionStrings("ETP_OPS_ConnectionString").ConnectionString, String)
            Dim connection As New SqlConnection(connectionString)
            Dim command As New SqlCommand(connectionString, connection)
 
            command = New SqlCommand("sp_Fix_Order", connection)
            command.CommandType = CommandType.StoredProcedure
 
            command.Connection.Open()
            command.Parameters.Add("@IDOrder", SqlDbType.Int).Value = IDOrder
            command.ExecuteNonQuery()
            command.Connection.Close()
 
 
 
        End If
    Next
End Sub

 

 Thank you as always.

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 26 May 2015, 12:23 PM
Hello Allan,

If the value in the underlying database is "null", the Text property for the corresponding TableCell will contain the non-breaking white space entity "&nbsp;". This entity is included in the empty cells, so it could handle a IE7 bug with empty TD elements.

With the above in mind, in your condition you need to check if the Text property of the cell is equal to "&nbsp;".

Hope this helps.


Best Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Allan
Top achievements
Rank 2
Answers by
Konstantin Dikov
Telerik team
Share this question
or