Hi Angela,
Thank you for posting in the community!
Based on my understanding, you want to make the linkbutton column in the
datagrid to have no underline.
=========================================
Yes, just use "butTemp.ItemStyle.CssClass = "Buttoncolumn"" will not work.
That is because you just apply the css style on the <td> not the <a>
tag.(You can determine this through View the html source)
Actually, you can get what you want through apply the css style on the
linkbutton web control in the ButtonColumn. So you should hook into the
DataGrid.ItemCreated event, then loop through the columns and controls to
find the LinkButton control. Then apply the style sheet.
I have writen a sample code for you:
<STYLE TYPE="text/css">
.Buttoncolumn { color: darkred; font-size:14pt; text-decoration: none}
/* unvisited link */
.Buttoncolumn:visited { color: indianred; text-decoration: none}
/*visited link */
.Buttoncolumn:active { color: gold;text-decoration: none } /* active
link */
.Buttoncolumn:hover { color: darkgreen; text-decoration: none} /*hover
or mousover link */
</STYLE>
protected System.Web.UI.HtmlControls.HtmlForm Form1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=");
DataSet ds=new DataSet();
adapter.Fill(ds);
DataGrid dg=new DataGrid();
ButtonColumn bc=new ButtonColumn();
//bc.ItemStyle.CssClass="Buttoncolumn";
bc.ButtonType=ButtonColumnType.LinkButton;
bc.Text="LinkButton";
dg.ItemCreated +=new DataGridItemEventHandler(dg_ItemCreated);
dg.Columns.Add(bc);
dg.DataSource=ds;
dg.DataBind();
Form1.Controls.Add(dg);
}
}
private void dg_ItemCreated(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.Alterna
tingItem)
{
DataGridItem dgi=e.Item as DataGridItem;
foreach(Control c in dgi.Cells[0].Controls)
{
if(c is LinkButton)
{
LinkButton lb=c as LinkButton;
lb.CssClass="Buttoncolumn";
}
}
}
}
It will work well.
Note: in the css style sheet, I add "text-decoration: none" to the
unvisited link, which will make the unvisited link have no underline.
==================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice weekend!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.