Friday, September 30, 2005

How to open new window using �HyperLinkColumn� in datagrid.

How to open new window using “HyperLinkColumn” in datagrid.

Client Side

Opening window from Hyperlink column problem comes “In Parent Window text [Object] comes and child window open properly” When you try to open window like this


DataNavigateUrlFormatString ="javascript:varedit'LoyaltyRewardDetail.aspx?RewardID={0}',

'childwindow','width=600,height=450,scrollbars=yes, resizable=yes')"


Insead of “varedit” type “void” keyword then parent window will remain same.




HeaderText="Invoice Id" >





HeaderText="Program Name"

DataNavigateUrlFormatString =


'childwindow','width=600,height=450,scrollbars=yes, resizable=yes')" >


Server Side

1) Add OnItemDataBound="PointHistoryBinding" into datagrid.

2) Bound the column as it in client side.

2) write code behind (in this way you can add multiple parameter in queryString

protected void LoyalityHistoryBinding( object sender, DataGridItemEventArgs e )


if( e.Item.ItemType == ListItemType.Header )




string ProgID = e.Item.Cells[5].Text;

string RetailerId = e.Item.Cells[6].Text;

string ProgName = e.Item.Cells[3].Text;

string VersionId = e.Item.Cells[4].Text;

string ReachDate = e.Item.Cells[1].Text;

string passPageLink = "<a href='#'


scrollbars=yes, resizable=yes');\">{2}</a>";

string passType = Convert.ToString( DataBinder.Eval(e.Item.DataItem, "ProgramName") ).Trim();

e.Item.Cells[3].Text = String.Format(passPageLink,ProgID,



Another way to use Hyperlink column in datagrid with more then one parameter QueryString

("How do I specify more than one parameter for my HyperlinkColumn?")

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">


<asp:TemplateColumn HeaderText="Sample Column">


<asp:Hyperlink runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ProductName").ToString()%>' NavigateUrl='<%# "page1.aspx?id=" + DataBinder.Eval(Container.DataItem,"ProductId").ToString() + "&Name=" + DataBinder.Eval(Container.DataItem,"ProductName").ToString()%>' ID="Hyperlink1" NAME="Hyperlink1"/>





Ritesh Kumar Kesharwani

A D I T I , B A N G A L O R E
Software Professional
Cell : 011-91-9845657636

Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.

1 comment:

moniemovieman said...

Very cool of you to let us post to your blog. If you are interested in making $3,000 or more per week please check out my work from home website. Thanks again and take care!