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

Show the row's data of radgrid in radwindow

4 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gilbert
Top achievements
Rank 1
Gilbert asked on 05 Sep 2013, 08:13 AM
Hi,

I'm having a problem in showing the data of selected row of radgrid in radwindow. What I have tried is using double click on client event using this script:

function RowDblClick(sender, eventArgs) {
 window.radopen("ViewForum.aspx?ForumID=" + eventArgs.getDataKeyValue("ForumID"), "RadWindow1");
}
Basically, all I want is whenever a user double click on a row of radgrid, it will open the radwindow and show the contents of the radgrid row that they have selected but I'm really having problem doing that. I can open the radwindow if I double click on the row of radgrid but the problem is the content radwindow always shows the first row of radgrid, it doesn't change even if I click on a different row. Thank you in advance. This is the code for my grid and window:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ForumSource" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None"
                                            Height="520px" Skin="MetroTouch" Width="889px" OnItemCreated="RadGrid1_ItemCreated" CommandItemDisplay="Top">
                                            <MasterTableView DataSourceID="ForumSource" PageSize="13" DataKeyNames="ForumID" AutoGenerateColumns="False" ClientDataKeyNames="ForumID">
                                                <Columns>
                                                     
                                                </Columns>
                                            </MasterTableView>
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="true"></Selecting>
                                                    <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
                                                    <Scrolling AllowScroll="false" UseStaticHeaders="True" />
                                                </ClientSettings>
                                        </telerik:RadGrid>
                                        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
                                            <Windows>
                                                <telerik:RadWindow ID="RadWindow1" runat="server" Height="450" Width="800"    ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" Skin="MetroTouch">
                                                </telerik:RadWindow>
                                            </Windows>
                                        </telerik:RadWindowManager>


4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Sep 2013, 09:34 AM
Hello,

Forum.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Forum.aspx.cs" Inherits="Forum"
    EnableEventValidation="false" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <telerik:RadCodeBlock ID="telerikodeBlock1" runat="server">
        <script type="text/javascript">
            function RowDblClick(sender, eventArgs) {
                window.radopen("Default4.aspx?ForumID=" + eventArgs.getDataKeyValue("ID"), "RadWindow1");
            }
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Height="450" Width="800" ReloadOnShow="true"
                ShowContentDuringLoad="false" Modal="true" Skin="MetroTouch">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="true"></Selecting>
            <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
            <Scrolling AllowScroll="false" UseStaticHeaders="True" />
        </ClientSettings>
    </telerik:RadGrid>
    </form>
</body>
</html>

Forum.aspx.cs
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data1 = new[] {
           new { ID = 1, Name ="Name_1"},
           new { ID = 2, Name = "Name_2"},
           new { ID = 3, Name = "Name_3"},
           new { ID = 4, Name = "Name_4"},
           new { ID = 5, Name = "Name_5"}
       };
 
    RadGrid1.DataSource = data1;
}


Default4.aspx.cs
protected void Page_Load(object sender, EventArgs e)
   {
 
       if (Request.QueryString["ForumID"] != null)
       {
           Response.Write(Convert.ToString(Request.QueryString["ForumID"]));
       }
   }

I have tried with your code but not able to reproduce it.

http://screencast.com/t/glf00QhJb8j

Thanks,
Jayesh Goyani
0
Gilbert
Top achievements
Rank 1
answered on 05 Sep 2013, 11:29 AM
Hi Jayesh,

Thank you so much for your help. I have tried your code, the radwindow opens but it only shows the datakey of the table which is ForumID, what I need is, show all the data of the selected row in Radwindow. Let me post my complete code.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                                            <script type="text/javascript">
                                                 
                                                function RowDblClick(sender, eventArgs) {
                                                    window.radopen("ViewForum.aspx?ForumID=" + eventArgs.getDataKeyValue("ForumID"), "RadWindow1");
                                                }
                                            </script>
                                        </telerik:RadCodeBlock>
                                        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                                            <AjaxSettings>
                                                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                                                    <UpdatedControls>
                                                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="gridLoadingPanel"></telerik:AjaxUpdatedControl>
                                                    </UpdatedControls>
                                                </telerik:AjaxSetting>
                                            </AjaxSettings>
                                        </telerik:RadAjaxManager>
                                        <telerik:RadAjaxLoadingPanel runat="server" ID="gridLoadingPanel"></telerik:RadAjaxLoadingPanel>
                                        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ForumSource" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None"
                                            Height="520px" Skin="MetroTouch" Width="889px">
                                            <MasterTableView DataSourceID="ForumSource" PageSize="13" DataKeyNames="ForumID" AutoGenerateColumns="False" ClientDataKeyNames="ForumID">
                                                <Columns>
                                                    <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                                                        <ItemTemplate>
                                                            <asp:HyperLink ID="EditLink" runat="server" Text="Read"></asp:HyperLink>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridBoundColumn DataField="ForumID" FilterControlAltText="Filter ForumID column" HeaderText="ForumID" SortExpression="ForumID" UniqueName="ForumID" DataType="System.Int32" ReadOnly="True" Visible="false">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="UserID" FilterControlAltText="Filter UserID column" HeaderText="Author" SortExpression="UserID" UniqueName="UserID">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="Subject" FilterControlAltText="Filter Subject column" HeaderText="Subject" SortExpression="Subject" UniqueName="Subject">
                                                        <HeaderStyle Wrap="false" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="Category" FilterControlAltText="Filter Category column" HeaderText="Category" SortExpression="Category" UniqueName="Category">
                                                        <HeaderStyle Wrap="false" />
                                                        <ItemStyle Wrap="false" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="ArticleDate" DataType="System.DateTime" FilterControlAltText="Filter ArticleDate column" HeaderText="Article Date" SortExpression="ArticleDate" UniqueName="ArticleDate">
                                                        <HeaderStyle Wrap="false" />
                                                        <ItemStyle Wrap="false" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="ForumBody" FilterControlAltText="Filter ForumBody column" HeaderText="ForumBody" SortExpression="ForumBody" UniqueName="ForumBody" Visible="false">
                                                    </telerik:GridBoundColumn>
                                                </Columns>
                                            </MasterTableView>
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="true"></Selecting>
                                                    <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
                                                    <Scrolling AllowScroll="false" UseStaticHeaders="True" />
                                                </ClientSettings>
                                        </telerik:RadGrid>
                                        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
                                            <Windows>
                                                <telerik:RadWindow ID="RadWindow1" runat="server" Height="450" Width="800" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" Skin="MetroTouch">
                                                </telerik:RadWindow>
                                            </Windows>
                                        </telerik:RadWindowManager>
                                        <asp:SqlDataSource ID="ForumSource" runat="server" ConnectionString="<%$ ConnectionStrings:ForumConnectionString %>" SelectCommand="SELECT [ForumID], [UserID], [Subject], [Category], [ArticleDate], [ForumBody] FROM [Tbl_Forum]"></asp:SqlDataSource>
This is the code for the other ViewForum.aspx:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="MetroTouch" DecoratedControls="All" />
            <span class="title">
                <asp:Label ID="ForumIDLabel" runat="server" Text=""></asp:Label></span>
            <span class="title">
                <asp:Label ID="UserIDLabel" runat="server" Text=""></asp:Label></span>
            <span class="title">
                <asp:Label ID="SubjectLabel" runat="server" Text=""></asp:Label></span>
            <span class="title">
                <asp:Label ID="BodyLabel" runat="server" Text=""></asp:Label>
            </span>
 
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ForumConnectionString %>" SelectCommand="SELECT [ForumID], [UserID], [Subject], [Category], [ArticleDate], [ForumBody] FROM [Tbl_Forum]">
            <SelectParameters>
                <asp:QueryStringParameter Name="ForumID" QueryStringField="ForumID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

And this the code behind:

 Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Request.QueryString("ForumID") IsNot Nothing Then
            Response.Write(Convert.ToString(Request.QueryString("ForumID")))
            ForumIDLabel.Text = Request.QueryString(Convert.ToString("ForumID"))
            UserIDLabel.Text = Request.QueryString("UserID")
            SubjectLabel.Text = Request.QueryString("Subject")
            BodyLabel.Text = Request.QueryString("ForumBody")
        End If


    End Sub

0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Sep 2013, 12:28 PM
Hello,

Please update below code in your existing code.

............
............
<MasterTableView DataSourceID="ForumSource" PageSize="13" DataKeyNames="ForumID,ForumBody" AutoGenerateColumns="False" ClientDataKeyNames="ForumID,ForumBody">
............
............


function RowDblClick(sender, eventArgs) {
               var _UserID = eventArgs.get_item().get_cell("UserID").innerHTML;
               var _Subject = eventArgs.get_item().get_cell("Subject").innerHTML;
 
               var _ForumID = eventArgs.getDataKeyValue("ForumID");
               var _ForumBody = eventArgs.getDataKeyValue("ForumBody");
 
               window.radopen("Default4.aspx?ForumID=" + _ForumID +
               "&ForumBody=" + _ForumBody +
               +"&Subject=" + _Subject
               + "&UserID=" + _UserID, "RadWindow1");
           }

protected void Page_Load(object sender, EventArgs e)
    {
 
        if (Request.QueryString["ForumID"] != null)
        {
            ForumIDLabel.Text = Convert.ToString(Request.QueryString["ForumID"]);
            UserIDLabel.Text = Convert.ToString(Request.QueryString["UserID"]);
            SubjectLabel.Text = Convert.ToString(Request.QueryString["Subject"]);
            BodyLabel.Text = Convert.ToString(Request.QueryString["ForumBody"]);
        }
    }



Thanks,
Jayesh Goyani
0
Gilbert
Top achievements
Rank 1
answered on 05 Sep 2013, 01:26 PM
It's working now. Thank you so much for your help. I really appreciate it. 
Tags
Grid
Asked by
Gilbert
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Gilbert
Top achievements
Rank 1
Share this question
or