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

RadGrid with a Redirect

4 Answers 405 Views
Grid
This is a migrated thread and some comments may be shown as answers.
M
Top achievements
Rank 1
M asked on 07 Feb 2011, 11:55 PM
I'm trying to Display the selected record in a asp.formview on the same page as the RadGrid.
When I click the 'Select' (GridButtonColumn) Button no Redirect occurs.
If I type in the entire Page URL with a QueryString value (http://10.0.0.110/Listing1.aspx?id=781) the formview displays the record.

Here is the code:

<telerik:RadGrid ID="RadGrid1" runat="server" 
                    AllowFilteringByColumn="True" 
                    AllowPaging="True" 
                    AllowSorting="True"
                    DataSourceID="SqlDataSource1" 
                    GridLines="None" 
                    Height="700px" 
                    PageSize="20"
                    <ClientSettings AllowColumnsReorder="True"
                        <Selecting AllowRowSelect="True" /> 
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                    </ClientSettings
                    <MasterTableView datasourceid="SqlDataSource1" DataKeyNames="id"
                        <Columns
                            <telerik:GridButtonColumn CommandName="Redirect" Text="Select" ButtonType="PushButton" UniqueName="ButtonColumn"
                                <HeaderStyle Width="70px" /> 
                            </telerik:GridButtonColumn>  
                        </Columns
                        <RowIndicatorColumn
                            <HeaderStyle Width="20px"></HeaderStyle
                        </RowIndicatorColumn
                        <ExpandCollapseColumn
                            <HeaderStyle Width="20px"></HeaderStyle
                        </ExpandCollapseColumn
                        <NoRecordsTemplate
                            Sorry No Records Found, Modify your search and try again. 
                        </NoRecordsTemplate
                    </MasterTableView
                    <PagerStyle Position="TopAndBottom" /> 
                </telerik:RadGrid
CodeBehind:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    
        if (e.CommandName == "Redirect"
        
            GridDataItem item = (GridDataItem)e.Item; 
            string value = item.GetDataKeyValue("id").ToString(); // Get the value in clicked row   
            // Save the required  value in session   
            string url = "listing1.aspx?id=" + value; 
            Response.Redirect(url); 
        
    }

Thank you in advance!
Mike

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Feb 2011, 09:31 AM
Hello Mike,


If the controls are placed in same page, then you can achieve this setting the "SelectParameters" rather than redirecting the page.

Sample code, you can find here.
<telerik:RadGrid ID="RadGrid1" TabIndex="1" AllowFilteringByColumn="true" ShowGroupPanel="True"
    AllowMultiRowSelection="false" ShowStatusBar="true" runat="server" DataSourceID="SqlDataSource1"
    AutoGenerateColumns="false" PageSize="10" AllowSorting="True" AllowPaging="True">
      <MasterTableView HierarchyDefaultExpanded="false" TableLayout="Fixed" AllowMultiColumnSorting="True"
                CommandItemDisplay="Top" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1">
               <Columns>
                    <telerik:GridButtonColumn CommandName="Select" Text="Select">
                    </telerik:GridButtonColumn>
             . . .
            </MasterTableView>
        </telerik:RadGrid>
 
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Customers WHERE CustomerID=@CustomerID"
    runat="server">
    <SelectParameters>
        <asp:ControlParameter ControlID="RadGrid1" PropertyName="SelectedValue" Name="CustomerID" />
    </SelectParameters>
</asp:SqlDataSource>
 
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2" Height="206px"
    BorderStyle="Solid" BorderColor="Black" Width="347px">
   <ItemTemplate>
     . . .
 



-Shinu.
0
M
Top achievements
Rank 1
answered on 08 Feb 2011, 03:18 PM
Something else is missing.
It still isn't displaying the Formview.
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
    </telerik:RadStyleSheetManager>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <table style="background-color: #cdeafe">
        <tr>
            <td valign="top" width="450">
                <telerik:RadGrid ID="RadGrid1" runat="server" 
                    AllowFilteringByColumn="True" 
                    AllowPaging="True" 
                    AllowSorting="True"
                    DataSourceID="SqlDataSource1" 
                    GridLines="None" 
                    Height="700px" 
                    PageSize="15">
                    <ClientSettings AllowColumnsReorder="True">
                        <Selecting AllowRowSelect="True" />
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                    </ClientSettings>
                    <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="id">
                        <Columns>
                            <telerik:GridButtonColumn CommandName="Select" Text="Select" ButtonType="PushButton" UniqueName="ButtonColumn">
                                <HeaderStyle Width="70px" />
                            </telerik:GridButtonColumn
                        </Columns>
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
                        <NoRecordsTemplate>
                            Sorry No Records Found, Modify your search and try again.
                        </NoRecordsTemplate>
                    </MasterTableView>
                    <PagerStyle Position="TopAndBottom" />
                </telerik:RadGrid>
                  
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                    SelectCommand="SELECT [id], [listing_id] FROM [tbl_listings] ORDER BY [listing_id]"></asp:SqlDataSource>
            </td>
</tr>
</table>
       
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    <telerik:AjaxUpdatedControl ControlID="SqlDataSource1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="SqlDataSource1">
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
<br /><br />
<table>
    <tr>
        <td>
        here
            <asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource2">
                <EditItemTemplate>
                    id:
                    <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                    <br />
                    listing_id:
                    <asp:TextBox ID="listing_idTextBox" runat="server" Text='<%# Bind("listing_id") %>' />
                    <br />
                    
                    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                     <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                </EditItemTemplate>
                <InsertItemTemplate>
                    listing_id:
                    <asp:TextBox ID="listing_idTextBox" runat="server" Text='<%# Bind("listing_id") %>' />
                    <br />
                    
                    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                     <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                </InsertItemTemplate>
                <ItemTemplate>
                    id:
                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                    <br />
                    listing_id:
                    <asp:Label ID="listing_idLabel" runat="server" Text='<%# Bind("listing_id") %>' />
                    <br />
                      
                </ItemTemplate>
            </asp:FormView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT [id], listing_id] FROM [tbl_listings] WHERE ([id] = @id)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="RadGrid1" Name="id" PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
</table>
Something must be missing.
I don't see it.

Thanks,
Mike
0
Shinu
Top achievements
Rank 2
answered on 09 Feb 2011, 05:52 AM
Hello Mike,


You need to set the AjaxManager - AjaxSettings in way that RadGrid1 updates FormView1 to get the functionality.


Try the following setting and see whether it helps:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                <telerik:AjaxUpdatedControl ControlID="FormView1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="SqlDataSource1">
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>



-Shinu.
0
M
Top achievements
Rank 1
answered on 10 Sep 2011, 03:57 PM
Thank you that worked.
Tags
Grid
Asked by
M
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
M
Top achievements
Rank 1
Share this question
or