ASP.NET - row bold inside gridview

Asked By Anjali agarwal on 17-Aug-11 12:09 AM

Hi All,
 

I have a gridview. One column of the gridview has linkbuttons in it. Whenever the user clicks on the link buttn, I am making that row bold. Below is my code, the code is not working properly. I mean it is not making the row bold.

protected void ID_Link_Click(object sender, EventArgs e) 
  { 
   
       LinkButton btn = (LinkButton)sender; 
      GridDataItem row = (GridDataItem)btn.NamingContainer; 
      row.Style.Add(HtmlTextWriterStyle.FontWeight, "Bold"); 
   
   
}
Somehow the row that I am clicking on is not becoming bold. I was wondering if someone an help me with this. I really don't want to do this coding in javascript.
 
Any help will be appreciated.


Jitendra Faye replied to Anjali agarwal on 17-Aug-11 12:20 AM
Follow these steps-

Step1: design your aspx page like this-

<ItemTemplate>

<asp:LinkButton ID="lnkBtn" runat="server" Text="Your Text" CommandName ="Change"></asp:LinkButton>

</ItemTemplate>


Step2:  implement GridViewRowCommand Event Like this-

public void GV1_RowCommandEvent(object sender, GridViewCommandEventArgs e)

{

if (e.CommandName == "change")

{

GridView1.Rows[e.Row.RowIndex].Style.Add(HtmlTextWriterStyle.FontWeight, "Bold");

}

}


Try this code and let me know.

Riley K replied to Anjali agarwal on 17-Aug-11 12:35 AM
Try this way

public void GridView1_RowCommandEvent(object sender, GridViewCommandEventArgs e)
 
{
 
if (e.CommandName == "makeBold")
 
{
 
e.Row.Style.Add(HtmlTextWriterStyle.FontWeight, "Bold");
 
}
 
}

Anoop S replied to Anjali agarwal on 17-Aug-11 01:35 AM
simply use like this way

e.Row.Font.Bold = true; //Make the font bold

for eg
http://msdn.microsoft.com/en-us/library/ms972833.aspx
http://www.simple-talk.com/dotnet/asp.net/take-row-level-control-of-your-gridview/
Ravi S replied to Anjali agarwal on 17-Aug-11 03:14 AM
hi

try this

protected void grvemployee_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      //this will be DataKey of the row
      int employeeId = (int)grvemployee.DataKeys[e.Row.RowIndex].Value;
 
      if (Session["EmployeeIds"] != null)
      {
        // get the arraylist from the session values
        employeeIds = (ArrayList)Session["EmployeeIds"];
 
        if (employeeIds != null)
        {
          //If the DataKey is in the arraylist then change the row color.
          if (employeeIds.Contains(employeeId))
          {
            e.Row.BackColor = System.Drawing.Color.Red;
            e.Row.Style.Add(HtmlTextWriterStyle.FontWeight, "Bold");
 
          }
        }
      }
    }
  }

refer
http://forums.asp.net/t/1679174.aspx/1?making+the+grid+row+bold+whenever+user+clicks+on+linkbutton

http://stackoverflow.com/questions/2073404/how-to-make-row-in-gridview-bold-and-regular-programatically-in-c-3-5
Radhika roy replied to Anjali agarwal on 17-Aug-11 09:46 AM

 

 Try this code-

The button on which you want to select a particular row add OnClick event, in your case
 

<ItemStyle Width="50px" BorderWidth="1" VerticalAlign="Top" />
<ItemTemplate>
<asp:LinkButton runat="server" CommandName='<%#Eval("ExpectedDate") %>' ID="btnSelect" CommandArgument='<%#Eval("MemberID") %>' Text="Select" OnClick="select_click"
></asp:LinkButton>
</ItemTemplate>

Then in page code behind

public void select_click(object sender, EventArgs e)
{
GridViewRow selectedRow = ((Control)sender).Parent.NamingContainer as GridViewRow; selectedRow .Style.Add(HtmlTextWriterStyle.FontWeight, "Bold"); 
}

 
Hope this will help you.