More in this section

Forums / Developing with Sitefinity / I have a problem with selecting a row

I have a problem with selecting a row

1 posts, 0 answered
  1. mathieu cupryk
    mathieu cupryk avatar
    9 posts
    Registered:
    20 Jul 2012
    09 Aug 2012
    Link to this post
    I want to capture the row value id of a grid. The first time I select a row. It gets stuck and if I try to select another one it goes back to the first selection.  It seems to be the ajaxpanel. any help would be great.
    <%@ Control Language="C#" AutoEventWireup="true" EnableViewState="true" Debug="true"
        CodeBehind="Orders.ascx.cs" Inherits="Schedule.Controls.Orders.Orders" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <style type="text/css">
        .RadGrid th
        {
            font: bold 11px tahoma;
            white-space: nowrap;
        }
    </style>
    <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
          <script type="text/javascript">
            function GridCreated(sender, eventArgs) {
                sender.get_element().focus();
            }
            function RowSelected(sender, eventArgs) {
                $find("<%= RadAjaxPanel1.ClientID %>").ajaxRequestWithTarget("<%= RadGrid1.UniqueID %>", "RowClick;" + eventArgs.get_itemIndexHierarchical());
            }
        </script>-
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1"
            ShowStatusBar="True" Skin="Windows7" GridLines="None" Width="99%" CellSpacing="0"
            CellPadding="0" OnItemCommand="RadGrid1_ItemCommand" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
            <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="true" />
                <ClientEvents OnGridCreated="GridCreated" OnRowSelected="RowSelected" />
            </ClientSettings>
            <SelectedItemStyle CssClass="SelectedItem"></SelectedItemStyle>
            <MasterTableView DataKeyNames="OrderID,DepartmentID" ClientDataKeyNames="OrderID,DepartmentID"
                AutoGenerateColumns="False" Width="100%">
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridClientSelectColumn />
                    <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" FilterControlAltText="Filter OrderID column"
                        HeaderText="OrdID" ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="OrderName" FilterControlAltText="Filter OrderName column"
                        HeaderText="Ord Name" SortExpression="OrderName" UniqueName="OrderName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DivisionDepartment" Visible="false" FilterControlAltText="Filter DivisionDepartment column"
                        HeaderText="DivDep" SortExpression="DivisionDepartment" UniqueName="DivisionDepartment">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DepartmentID" FilterControlAltText="Filter DepartmentID column"
                        HeaderText="DepID" SortExpression="DepartmentID" UniqueName="DepartmentID" ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Department" FilterControlAltText="Filter Department column"
                        HeaderText="Dep" SortExpression="Department" UniqueName="Department">
                    </telerik:GridBoundColumn>
                    <telerik:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean" FilterControlAltText="Filter IsActive column"
                        HeaderText="Active" SortExpression="IsActive" UniqueName="IsActive">
                    </telerik:GridCheckBoxColumn>
                    <telerik:GridBoundColumn DataField="Date" FilterControlAltText="Filter Date column"
                        DataFormatString="{0:D}" HeaderText="Date" SortExpression="Date" UniqueName="Date"
                        ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CreatorID" FilterControlAltText="Filter CreatorID column"
                        HeaderText="Creator" SortExpression="CreatorID" UniqueName="CreatorID">
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
            </MasterTableView>
            <PagerStyle Mode="NextPrevAndNumeric" />
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
        </telerik:RadGrid>
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </telerik:RadAjaxPanel>
    <telerik:RadGrid ID="RadGrid2" ShowStatusBar="True" runat="server" AllowPaging="True"
        PageSize="5" DataSourceID="SqlDataSource2" GridLines="None" Width="99%" CellSpacing="0"
        Skin="Windows7">
        <MasterTableView Width="100%" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="UnitNumber" HeaderText="UnitNumber" SortExpression="UnitNumber"
                    UniqueName="UnitNumber" FilterControlAltText="Filter UnitNumber column">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ClassCode" HeaderText="ClassCode" SortExpression="ClassCode"
                    UniqueName="ClassCode" FilterControlAltText="Filter ClassCode column">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Capital" HeaderText="Capital" SortExpression="Capital"
                    UniqueName="Capital" DataType="System.Decimal" FilterControlAltText="Filter Capital column"
                    ReadOnly="True">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="NewUnitNumber" FilterControlAltText="Filter NewUnitNumber column"
                    HeaderText="NewUnitNumber" ReadOnly="True" SortExpression="NewUnitNumber" UniqueName="NewUnitNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="OpRate" DataType="System.Double" FilterControlAltText="Filter OpRate column"
                    HeaderText="OpRate" ReadOnly="True" SortExpression="OpRate" UniqueName="OpRate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="LinkNumber" DataType="System.Int32" FilterControlAltText="Filter LinkNumber column"
                    HeaderText="LinkNumber" SortExpression="LinkNumber" UniqueName="LinkNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="NewLinkNumber" DataType="System.Int32" FilterControlAltText="Filter NewLinkNumber column"
                    HeaderText="NewLinkNumber" SortExpression="NewLinkNumber" UniqueName="NewLinkNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Make" FilterControlAltText="Filter Make column"
                    HeaderText="Make" SortExpression="Make" UniqueName="Make">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Model" FilterControlAltText="Filter Model column"
                    HeaderText="Model" SortExpression="Model" UniqueName="Model">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <PagerStyle Mode="NextPrevAndNumeric" />
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>
    <br />
    <br />
    <%--    <strong>Orders details:</strong>
        <telerik:RadGrid ID="RadGrid3" ShowStatusBar="true" runat="server" AllowPaging="True"
            PageSize="5" DataSourceID="SqlDataSource3" GridLines="None" Width="95%" HorizontalAlign="NotSet">
            <MasterTableView Width="100%" AutoGenerateColumns="False" DataKeyNames="OrderID"
                DataSourceID="SqlDataSource3">
                <Columns>
                    <telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Unit price" SortExpression="UnitPrice"
                        UniqueName="UnitPrice">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity"
                        UniqueName="Quantity">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Discount" HeaderText="Discount (%)" SortExpression="Discount"
                        UniqueName="Discount">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <PagerStyle Mode="NextPrevAndNumeric" />
        </telerik:RadGrid>--%>
    <br />
    <br />
    <br />
       
    <br />
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:MinotaurConnectionStringProd %>"
        SelectCommand="SELECT 
    dbo.Orders.OrderID AS OrderID,
    dbo.Orders.OrderName AS OrderName,
    dbo.Departments.DeptDescription AS Department,
    dbo.Departments.DeptNumber AS DepartmentID,
    dbo.Orders.Active As IsActive,
    dbo.Orders.DivisionDepartment,
    CONVERT(VARCHAR(19), dbo.Orders.Date ,120) AS Date,
    dbo.Orders.CreatorID,
    dbo.Orders.LastOpID, CONVERT(VARCHAR(19),
    dbo.Orders.LastOpDate, 120) AS LastOpDate FROM dbo.Departments
    INNER JOIN dbo.Orders ON dbo.Departments.DeptNumber = dbo.Orders.DivisionDepartment order by dbo.Orders.OrderID
    " runat="server"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:MinotaurConnectionStringProd %>"
        SelectCommand="SELECT Minotaur.dbo.Units.RPUnitNumber AS UnitNumber, RTAFleet.dbo.vehfile.vehicle_location AS ClassCode, Capital = CASE WHEN Minotaur.dbo.Units.NewLinkNumber IS NULL THEN 0 ELSE CASE WHEN (SELECT SUM(Parts + Labour) AS Cap FROM PurchaseItems WHERE SnapShotID = 1 AND LinkNumber = Minotaur.dbo.Units.NewLinkNumber) IS NULL THEN 0 ELSE (SELECT SUM(Parts + Labour) AS Cap FROM PurchaseItems WHERE SnapShotID = 1 AND LinkNumber = Minotaur.dbo.Units.NewLinkNumber) END END ,NewUnitNumber=(SELECT Minotaur.dbo.Units.RPUnitNumber FROM Minotaur.dbo.Units WHERE Minotaur.dbo.Units.LinkNumber = NewLinkNumber) ,OpRate= CASE WHEN (SELECT U1.OpRate FROM Minotaur.dbo.Units AS U1 WHERE U1.SnapShotID = 1 AND U1.LinkNumber = Minotaur.dbo.Units.NewLinkNumber) IS NULL THEN CASE WHEN Minotaur.dbo.OpRate.UsageRate IS NULL THEN CAST(0.00 AS DECIMAL) ELSE Minotaur.dbo.OpRate.UsageRate END ELSE ROUND((SELECT U1.OpRate FROM Minotaur.dbo.Units AS U1 WHERE U1.SnapShotID = 1 AND U1.LinkNumber = Minotaur.dbo.Units.NewLinkNumber),2) END, Minotaur.dbo.Units.LinkNumber AS LinkNumber, Minotaur.dbo.Units.NewLinkNumber AS NewLinkNumber, RTAFleet.dbo.vehfile.vehicle_make AS Make, RTAFleet.dbo.vehfile.vehicle_model AS Model FROM (Minotaur.dbo.XrefNum INNER JOIN Minotaur.dbo.Units ON Minotaur.dbo.XrefNum.RPLinkNumber = Minotaur.dbo.Units.LinkNumber) LEFT JOIN Minotaur.dbo.OpRate ON Minotaur.dbo.Units.[Type] = Minotaur.dbo.OpRate.[Type] AND Minotaur.dbo.Units.Usage = Minotaur.dbo.OpRate.Usage AND Minotaur.dbo.Units.Engine = Minotaur.dbo.OpRate.Engine AND Minotaur.dbo.OpRate.SnapShotID=1, RTAFleet.dbo.vehfile WHERE  RTAFleet.dbo.vehfile.link_number = Minotaur.dbo.XrefNum.RTALinkNumber AND Minotaur.dbo.Units.DisposalOrderID = @OrderID AND Minotaur.dbo.Units.SnapShotID = 1 ORDER BY [LinkNumber] DESC"
        runat="server">
        <SelectParameters>
            <asp:ControlParameter ControlID="RadGrid1" DefaultValue="61" Name="OrderID" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
     
     
       public partial class Orders : UserControl
        {
     
     
     
     
            protected void Page_Load(object sender, EventArgs e)
            {
            }
     
            protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
            {
     
                Label1.Text = "RadAjaxManager AJAX call at:" + DateTime.Now.ToLongTimeString();
     
            }
            protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
            {
                //RadGrid2.SelectedIndexes.Clear();
                if (e.CommandName == "RowClick")
                {
     
                    Label1.Text = "";
                    Label1.Text = (e.Item as GridDataItem)["OrderID"].Text;
                    if (Label1.Text != "")
                    {
                        //To Save a Value in a session
                        Session["OrderID"] = Label1.Text;  // Lets say its a string
                    }
                    else
                    {
                        Session["OrderID"] = null;
     
                    }
                }
            }
     
           
            protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
            {
                GridDataItem item = RadGrid1.SelectedItems[0] as GridDataItem;
                //SqlDataSource2.SelectParameters["OrderID"].DefaultValue = item["OrderID"].Text;
            }


1 posts, 0 answered