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

Example:

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

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

Solution

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

Example;

<asp:BoundColumn

DataField="InvoiceId"

HeaderText="Invoice Id" >

</asp:BoundColumn>

<asp:HyperLinkColumn

DataTextField="programname"

DataNavigateUrlField="RewardID"

HeaderText="Program Name"

DataNavigateUrlFormatString =

"javascript:void window.open('LoyaltyRewardDetail.aspx?RewardID={0}',

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

</asp:HyperLinkColumn>

Server Side

1) Add OnItemDataBound="PointHistoryBinding" into datagrid.

2) Bound the column as it in client side.

2) write code behind C#.net (in this way you can add multiple parameter in queryString

protected void LoyalityHistoryBinding( object sender, DataGridItemEventArgs e )

{

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

{

return;

}

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='#'

onclick=\"window.open('LoyaltyDetail.aspx?ProgId={0}&ReachDate={1}&ProgName={2}&VersionId={3}&RetailerId={4}','childwindow','width=600,height=450,

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,

ReachDate,ProgName,VersionId,RetailerId,passType);

}

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">

<Columns>

<asp:TemplateColumn HeaderText="Sample Column">

<ItemTemplate>

<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"/>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:DataGrid>





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.

How to Change Mouse Pointer server side for button control.

How to Change Mouse Pointer server side for button control.

 

If button control are deactivate then you want to change Mouse Pointer when user go to that button

 

When button deactivate

BtnDelete.enabled = false;

btnDelete.Style["CURSOR"] = "default";

 

When button active

btnDelete.Style["CURSOR"] = "hand";

BtnDelete.enabled = true;

 



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.

How to Control button event in Web Forms when user press Enter button

How to Control button event in Web Forms when user press Enter button

 

Suppose you have more then one button (three button named: btnFirstButton,btnSecondButton,btnThirdButton) in your web page and after enter button press

First button called.

If you want some particular button should called after enter button press then you can do one this after come out from some control (textbox) you can call one JavaScript function

In textbox onkeypress client side (onkeypress="return OnLevelBlur(event);).

 

<asp:textbox id="txtbox1" Runat="server" MaxLength="10" onkeypress="return OnLevelBlur(event);">

 

JavaScript Function

 

function OnLevelBlur(e)

{

char = String.fromCharCode(e.keyCode);

xCode=char.charCodeAt(0);

if (xCode == 13)

{

document.all["btnFirstButton"].disabled="false"; document.all["btnSecondButton"].disabled="false"; document.Form1.txtbox1.focus();

}

}

 

How it’s Work

 

Basically you catch Enter button events and put the condition that if enter button pressed then disable btnFirstButton  and btnSecondButton  then automatically btnThirdButton click event will fire and after server trip  that two buttons btnFirstButton and btnSecondButton will active again.

 

Summary

 

You are disabling some button which you don’t want to click after enter button.

       

 



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.