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

Setting Property on User Control

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 2
Elliott asked on 14 Jun 2010, 06:05 PM
I am creating an order entry page which has a large number of items (30-50K)
On the doubleclick a user control opens up containing the part number, description, cost, etc.
is there a way to pass into (or pull up) the customer number?
I could always add it to the data source but that is increasing the size of an already large data table
the add is on a click event in the control - I could change it to trigger an Insert (adding it to the order table, not the items table)
I am working in VS2010 ASP.NET 4.0
the grid is filled through LINQ to SQL

from the main page:
<asp:Content ID="cntBody" ContentPlaceHolderID="cpHolder" Runat="Server">
    <telerik:RadScriptManager ID="rsManager" runat="server" />
    <telerik:RadCodeBlock ID="rcBlock" runat="server">
        <script type="text/javascript">
        function RowDblClick(sender, eventArgs) {
            sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
        }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="raManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgItems">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgItems" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

the grid (from the main page)
    <telerik:RadGrid ID="rgItems" AutoGenerateColumns="False" AllowPaging="True"
            runat="server" AllowFilteringByColumn="True" AllowSorting="True" GridLines="None">
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        <MasterTableView DataKeyNames="ItemID" EditMode="PopUp">
        <Columns>
            <telerik:GridBoundColumn UniqueName="ItemID" DataField="ItemID" Visible="False">
            </telerik:GridBoundColumn>
...
        </Columns>
        <EditFormSettings UserControlName="OrderItem.ascx" EditFormType="WebUserControl">
        </EditFormSettings>
        </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
    </telerik:RadGrid>
and code behind
Partial Class Items
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim DivisionID As Integer = 3
        Dim ws As CommonFunctions
        If Page.IsPostBack Then
        Else
            ws = New CommonFunctions
            rgItems.DataSource = ws.GetItems(DivisionID)
            rgItems.DataBind()
        End If
        ws = Nothing
    End Sub

    Protected Sub rgItems_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgItems.NeedDataSource
        Dim DivisionID As Integer = 3
        Dim ws As New CommonFunctions
        rgItems.DataSource = ws.GetItems(DivisionID)
        ws = Nothing
    End Sub

End Class

the user control HTML
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="OrderItem.ascx.vb" Inherits="OrderItem" %>
<table border="1" cellpadding="1" cellspacing="1" style="background-color:#CC9900;">
<tr>
<td>ItemID</td>
<td>
    <asp:Label ID="lblItemID" Text='<%# DataBinder.Eval( Container, "DataItem.ItemID") %>' runat="server" />
</td>
</tr>
...
<tr>
<td>
    <asp:Button ID="btnAddtoOrder" Text="Add to Order" CommandName="AddtoOrder" runat="server" />
</td>
<td align="right">
    <asp:Button ID="btnCancel" Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server" />
</td>
</tr>
</table>
and code behind for the user control
Imports System.Data

Partial Class OrderItem
    Inherits System.Web.UI.UserControl

    Private _dataItem As Object
    Public Property DataItem() As Object
        Get
            Return Me._dataItem
        End Get
        Set(ByVal value As Object)
            Me._dataItem = value
        End Set
    End Property
' where do I get this???????
    Private _dealerNumber As Int64
    Public Property DealerNumber() As Int64
        Get
            Return Me._dealerNumber
        End Get
        Set(ByVal value As Int64)
            Me._dealerNumber = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    End Sub

    Protected Sub btnAddtoOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddtoOrder.Click
        Dim ItemID, OrderItemID As Integer

        If Page.IsValid Then
        Else
            Exit Sub
        End If

        ItemID = CInt(lblItemID.Text)

        Dim ws As New CommonFunctions
        OrderItemID  = ws.AddToOrder(DealerNumber, ItemID, etc)
        ws = Nothing
    End Sub
End Class


1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 17 Jun 2010, 11:56 AM
Hello Marianne,

You can use RadGrid's ItemDataBound event to get reference to the UserControl in the EditForm and assign the appropriate values. Please refer to this help article (under Setting properties without using binding expressions).

Regards,
Rosen
the Telerik team
Tags
Grid
Asked by
Elliott
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or