RadGrid for ASP.NET

Collecting data in a new window Send comments on this topic.
Insert/Update/Delete records > Collecting data in a new window

Glossary Item Box

There are various cases in which you may want to get the content of the cells in a selected grid row (clicking a hyperlink in that row), pass this content in a query and open the results in a new window.
Such scenario is easily handled by Telerik RadGrid. Here is a sample implementation technique:
  1. We use GridHyperLink column with Target property set to  _blank to open a new window on user click;
  2. Hooking the ItemDataBound event of the grid we store the values of the cells for the clicked row in the NavigateUrl property of the Hyperlink in the GridHyperLinkColumn (passing them as QueryString arguments);
  3. In the page to which we navigate (Resources.aspx) we have five labels. Their text is set on PageLoad and Not Page.IsPostBack to display the details for the clicked row;
  4. The clicked row will be selected as we enabled client side selection (setting ClientSettings -> Selecting -> AllowRowSelect = True).

Default file (ASPX and code-behind)

ASPX/ASCX Copy Code
<rad:RadGrid ID="RadGrid1" DataSourceID="AccessDataSource1" runat="server">
<SelectedItemStyle BackColor="Aqua" />
<MasterTableView AutoGenerateColumns="True">
 
<Columns>
  
<rad:GridHyperLinkColumn HeaderText="Select row"
   
Target="_blank" Text="Display details in new window" UniqueName="HyperLinkColumn">
  
</rad:GridHyperLinkColumn>
 
</Columns>
</MasterTableView>
<ClientSettings>
   
<Selecting AllowRowSelect="True" />
</ClientSettings>
</
rad:RadGrid>
<
br />
<
asp:AccessDataSource ID="AccessDataSource1" DataFile="~/Grid/Data/Access/Nwind.mdb"
 
SelectCommand="SELECT TOP 10 CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers"
 
runat="server"></asp:AccessDataSource>
In the code-behind:
VB.NET Copy Code
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound
  If (TypeOf e.Item Is GridDataItem) Then
     Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)

     Dim link As HyperLink = CType(dataItem("HyperlinkColumn").Controls(0), HyperLink)
     link.NavigateUrl = "Resources.aspx?CompanyName=" & dataItem("CompanyName").Text & "&ContactName=" & dataItem("ContactName").Text &
     "&ContactTitle=" & dataItem("ContactTitle").Text & "&Address=" & dataItem("Address").Text & "&PostalCode=" & dataItem("PostalCode").Text
  End If
End Sub
C# Copy Code
protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) {
if (e.Item is GridDataItem)
{
 GridDataItem dataItem = (GridDataItem)e.Item;

 HyperLink link = (HyperLink)dataItem[
"HyperlinkColumn"].Controls[0];
 link.NavigateUrl =
"Resources.aspx?CompanyName=" + dataItem["CompanyName"].Text + "&ContactName=" + dataItem["ContactName"].Text
 +
"&ContactTitle=" + dataItem["ContactTitle"].Text + "&Address=" + dataItem["Address"].Text + "&PostalCode=" + dataItem["PostalCode"].Text;
}
}


Resources file (ASPX and code-behind)

ASPX Copy Code
<div>
<b>Company name:</b>
<br />
<asp:Label ID="lblCompanyName" runat="server" Text=""></asp:Label>
<br />
<b>Contact name:</b>
<br />
<asp:Label ID="lblContactName" runat="server" Text=""></asp:Label>
<br />
<b>Contact title:</b>
<br />
<asp:Label ID="lblContactTitle" runat="server" Text=""></asp:Label>
<br />
<b>Address:</b>
<br />
<asp:Label ID="lblAddress" runat="server" Text=""></asp:Label>
<br />
<b>Postal code:</b>
<br />
<asp:Label ID="lblPostalCode" runat="server" Text=""></asp:Label>
</
div>

And in the code-behind:

VB.NET Copy Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If (Not IsPostBack) Then
    lblCompanyName.Text = Request.QueryString("CompanyName")
    lblContactName.Text = Request.QueryString("ContactName")
    lblContactTitle.Text = Request.QueryString("ContactTitle")
    lblAddress.Text = Request.QueryString("Address")
    lblPostalCode.Text = Request.QueryString("PostalCode")
  End If
End Sub
C# Copy Code
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
 lblCompanyName.Text = Request.QueryString[
"CompanyName"];
 lblContactName.Text = Request.QueryString[
"ContactName"];
 lblContactTitle.Text = Request.QueryString[
"ContactTitle"];
 lblAddress.Text = Request.QueryString[
"Address"];
 lblPostalCode.Text = Request.QueryString[
"PostalCode"];
}
}

 

The following Knowledge Base article describes how to use Telerik RadWindow to display, edit, update and insert data in a new window:

http://www.telerik.com/support/knowledge-base/kb-article.aspx?b454K=xvb&b454T=oYw