why will this not work in C#

G

Guest

What i'm trying to do is allow the user click on a row in the datagrid and it
highlights the row. I have the select button for my grid and its hidden.
I can do this in VB.NET successfully with this same code but when i put it
in C# it does not work.

what am i missing?

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.SelectedItem)
{
e.Item.Attributes.Add("onmouseover",
"this.style.bacgroundcolor='#FFFFFF';this.style.cursor='hand'");
e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + " DataGrid1:"
+ "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");

}
}
 
H

Hans Kesting

Mike said:
What i'm trying to do is allow the user click on a row in the
datagrid and it highlights the row. I have the select button for my
grid and its hidden.
I can do this in VB.NET successfully with this same code but when i
put it in C# it does not work.

what am i missing?

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem | e.Item.ItemType ==
ListItemType.SelectedItem) {
e.Item.Attributes.Add("onmouseover",
"this.style.bacgroundcolor='#FFFFFF';this.style.cursor='hand'");
e.Item.Attributes.Add("onclick","javascript:__doPostBack('" + "
DataGrid1:" + "_ctl" + (e.Item.ItemIndex + 7) + ":_ctl0','')");

}
}

What exactly do you mean by "does not work"?

One thing I notice: you use "|", which is C# for "bitwise OR"
(with integer oparands).
I think you want "||" (C# for "boolean OR") (with boolean operands)

Hans Kesting
 
G

Guest

It doesn't work. It does not allow me to click on a row and highlight the
row, like it does in the VB.NET world.
 
H

Hans Kesting

Mike said:
It doesn't work. It does not allow me to click on a row and highlight
the row, like it does in the VB.NET world.

Is the mouseover code added (see html-source in the browser)? (probably not)

Did you change | to || (double-pipe) in your code?

Hans Kesting
 
H

Hans Kesting

Mike said:
yes its in the code and yes I added the || (which made no difference)

Then I don't know, apart from something I noticed just now:
you write "bacgroundcolor" in your post, which should be "backgroundcolor"
(but this is probably just a typo in your post)

Hans Kesting
 
G

Guest

I got it working thx

Hans Kesting said:
Then I don't know, apart from something I noticed just now:
you write "bacgroundcolor" in your post, which should be "backgroundcolor"
(but this is probably just a typo in your post)

Hans Kesting
 
Joined
Mar 6, 2009
Messages
1
Reaction score
0
Attribute.Add syntax

Hi, I am new to C# so this may be an easy one to spot ...
Why does this line of code work :

imgctrl.Attributes.Add("onmouseout", "this.src='products/images/zenzai_off.gif'");

but the following does not (the image does not change)

string imageOnUrl = "products/images/zenzai_on.gif";
imgctrl.Attributes.Add("onmouseover", "this.src= imageOnUrl");

Kind regards
 
Last edited:
Joined
Apr 22, 2011
Messages
1
Reaction score
0
You're missing the single quotes...

Hi, I am new to C# so this may be an easy one to spot ...
Why does this line of code work :

imgctrl.Attributes.Add("onmouseout", "this.src='products/images/zenzai_off.gif'");

but the following does not (the image does not change)

string imageOnUrl = "products/images/zenzai_on.gif";
imgctrl.Attributes.Add("onmouseover", "this.src= imageOnUrl");

Kind regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top