By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,639 Members | 2,000 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,639 IT Pros & Developers. It's quick & easy.

programatically setting the background property of a <td>

P: n/a
Gil
Hello,

I use VB.NET and have a series of linkbuttons that are inside individual
<td>s. Like this:

<td background="image.gif"><asp:linkbutton id="myID" runat="server"/></td>

I would like the background of the td to be different for the currently
selected linkbutton than for the other linkbuttons:

<td background="image1.gif"><asp:linkbutton id="myID1" runat="server"/> </td>
<td background="image2.gif"><asp:linkbutton id="myID2" runat="server"/></td>
<td background="image2.gif"><asp:linkbutton id="myID3" runat="server"/></td>
I tried several things before posting. First I tried to create a
<asp:literal/> and refer to that literal in by aspx.vb file. Thus I wanted
to programatically specify the image that would be displayed in the
background of my <td>:

If ...then
myLiteral = "<td background='image1.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

else
myLiteral = "<td background='image2.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

end if
This suffers from the problem that I can't refer to a linkbutton in my
literal without first having a tag appear in the html part of the .aspx code,
since the tag needs to be inside the <td>. See "Linkbutton Constructor" in
the .net framework class library.

Next I tried to do it by placing my linkbutton in the html portion of the
..aspx file by placing it inside a <asp:table>:

<asp:table>
<asp:tablerow>
<asp:tablecell>
<asp:linkbutton id=...>
</asp:tablecell>
</asp:tablerow>
</asp:table>

My hope was that I could then programatically specify the property of
<asp:tablecell>. This too suffered from the problem that my linkbutton could
not be contained in this <asp:table> arrangement.

Any help is sure appreaciated.
Thanks,
Gil
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

If you put your linkbuttons into the DataGrid and make some changes on
ItemDataBound evebt you can change the selected linkbtton background. You can
bind linkbutton's text on DataGrid's ItemDataBound event also.You can change
cell's background when cell is clicked or double clicked. If you can't make
this, I will send the detail sample code later.

Have a nice work,

"Gil" wrote:
Hello,

I use VB.NET and have a series of linkbuttons that are inside individual
<td>s. Like this:

<td background="image.gif"><asp:linkbutton id="myID" runat="server"/></td>

I would like the background of the td to be different for the currently
selected linkbutton than for the other linkbuttons:

<td background="image1.gif"><asp:linkbutton id="myID1" runat="server"/> </td>
<td background="image2.gif"><asp:linkbutton id="myID2" runat="server"/></td>
<td background="image2.gif"><asp:linkbutton id="myID3" runat="server"/></td>
I tried several things before posting. First I tried to create a
<asp:literal/> and refer to that literal in by aspx.vb file. Thus I wanted
to programatically specify the image that would be displayed in the
background of my <td>:

If ...then
myLiteral = "<td background='image1.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

else
myLiteral = "<td background='image2.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

end if
This suffers from the problem that I can't refer to a linkbutton in my
literal without first having a tag appear in the html part of the .aspx code,
since the tag needs to be inside the <td>. See "Linkbutton Constructor" in
the .net framework class library.

Next I tried to do it by placing my linkbutton in the html portion of the
.aspx file by placing it inside a <asp:table>:

<asp:table>
<asp:tablerow>
<asp:tablecell>
<asp:linkbutton id=...>
</asp:tablecell>
</asp:tablerow>
</asp:table>

My hope was that I could then programatically specify the property of
<asp:tablecell>. This too suffered from the problem that my linkbutton could
not be contained in this <asp:table> arrangement.

Any help is sure appreaciated.
Thanks,
Gil

Jul 21 '05 #2

P: n/a
Gil
Hi Aytac,

Thanks for the reply. Can you post the sample code.

Thanks again.
Gil

"Aytaç ÖZAY" wrote:
Hi,

If you put your linkbuttons into the DataGrid and make some changes on
ItemDataBound evebt you can change the selected linkbtton background. You can
bind linkbutton's text on DataGrid's ItemDataBound event also.You can change
cell's background when cell is clicked or double clicked. If you can't make
this, I will send the detail sample code later.

Have a nice work,

"Gil" wrote:
Hello,

I use VB.NET and have a series of linkbuttons that are inside individual
<td>s. Like this:

<td background="image.gif"><asp:linkbutton id="myID" runat="server"/></td>

I would like the background of the td to be different for the currently
selected linkbutton than for the other linkbuttons:

<td background="image1.gif"><asp:linkbutton id="myID1" runat="server"/> </td>
<td background="image2.gif"><asp:linkbutton id="myID2" runat="server"/></td>
<td background="image2.gif"><asp:linkbutton id="myID3" runat="server"/></td>
I tried several things before posting. First I tried to create a
<asp:literal/> and refer to that literal in by aspx.vb file. Thus I wanted
to programatically specify the image that would be displayed in the
background of my <td>:

If ...then
myLiteral = "<td background='image1.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

else
myLiteral = "<td background='image2.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

end if
This suffers from the problem that I can't refer to a linkbutton in my
literal without first having a tag appear in the html part of the .aspx code,
since the tag needs to be inside the <td>. See "Linkbutton Constructor" in
the .net framework class library.

Next I tried to do it by placing my linkbutton in the html portion of the
.aspx file by placing it inside a <asp:table>:

<asp:table>
<asp:tablerow>
<asp:tablecell>
<asp:linkbutton id=...>
</asp:tablecell>
</asp:tablerow>
</asp:table>

My hope was that I could then programatically specify the property of
<asp:tablecell>. This too suffered from the problem that my linkbutton could
not be contained in this <asp:table> arrangement.

Any help is sure appreaciated.
Thanks,
Gil

Jul 21 '05 #3

P: n/a
Hi Gill,

First of all sorry for response back late:( It's the code under, that you want

The first method is used with DataGrid's ItemCommand event, if u want to use
ItemCommand event, u will write the changeCellcolor code in this method.

The second code is used with DataGrid's ItemDataBound event, if u want to
use this method u don't need to wite anything in it.

private void dgGenel_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "update") {
// Set editable list item index if "update" button clicked next to the
item
dgGenel.EditItemIndex = e.Item.ItemIndex;
int dgID=-1;
dgID = (int)dgGenel.DataKeys[e.Item.ItemIndex];
Response.Redirect(Request.Url.ToString()+"&updateI D="+dgID);
}
}

private void dgGenel_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex == -1)
return;

int dgID=-1;
dgID = (int)dgGenel.DataKeys[e.Item.ItemIndex];

e.Item.Attributes.Add("OnDblClick", "window.location='" +
"http://"+Request.Url.Host+Request.Url.AbsolutePath+"?upda teID="+dgID+"'");

if (dgID == updateID)
e.Item.BackColor = Color.FromArgb(255, 255, 204);
else
{
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='#BDD3FB';this.style.c ursor='hand'");
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='White'");
e.Item.BackColor = Color.White;
}
}

Have a nice day,

"Gil" wrote:
Hi Aytac,

Thanks for the reply. Can you post the sample code.

Thanks again.
Gil

"Aytaç ÖZAY" wrote:
Hi,

If you put your linkbuttons into the DataGrid and make some changes on
ItemDataBound evebt you can change the selected linkbtton background. You can
bind linkbutton's text on DataGrid's ItemDataBound event also.You can change
cell's background when cell is clicked or double clicked. If you can't make
this, I will send the detail sample code later.

Have a nice work,

"Gil" wrote:
Hello,

I use VB.NET and have a series of linkbuttons that are inside individual
<td>s. Like this:

<td background="image.gif"><asp:linkbutton id="myID" runat="server"/></td>

I would like the background of the td to be different for the currently
selected linkbutton than for the other linkbuttons:

<td background="image1.gif"><asp:linkbutton id="myID1" runat="server"/> </td>
<td background="image2.gif"><asp:linkbutton id="myID2" runat="server"/></td>
<td background="image2.gif"><asp:linkbutton id="myID3" runat="server"/></td>
I tried several things before posting. First I tried to create a
<asp:literal/> and refer to that literal in by aspx.vb file. Thus I wanted
to programatically specify the image that would be displayed in the
background of my <td>:

If ...then
myLiteral = "<td background='image1.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

else
myLiteral = "<td background='image2.gif'><asp:linkbutton id='myID'
runat='server'/> </td>"

end if
This suffers from the problem that I can't refer to a linkbutton in my
literal without first having a tag appear in the html part of the .aspx code,
since the tag needs to be inside the <td>. See "Linkbutton Constructor" in
the .net framework class library.

Next I tried to do it by placing my linkbutton in the html portion of the
.aspx file by placing it inside a <asp:table>:

<asp:table>
<asp:tablerow>
<asp:tablecell>
<asp:linkbutton id=...>
</asp:tablecell>
</asp:tablerow>
</asp:table>

My hope was that I could then programatically specify the property of
<asp:tablecell>. This too suffered from the problem that my linkbutton could
not be contained in this <asp:table> arrangement.

Any help is sure appreaciated.
Thanks,
Gil

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.