1
votes

I have a query, output of which populates a gridview. The columns of gridview are not fixed, i.e except for 1st columns rest column count can vary.

Output table structure is roughly:

    name | week1 | week2
    stu1 | 23    | 0
    stu2 | 45    | 6

The column count varies because week no is not static. Is it possible to generate hyperlink in the cells where cell value is greater than zero? And if possible then how to get the row and column index on clicking the digit and redirecting to another page for details?

1
show gridview code. - 5377037

1 Answers

0
votes

you can do it in RowDataBound event , as given in msdn : GridView.RowDataBound Event

  void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      for(var cell in e.Row.Cells)
      {
       int val = 0; 
       if(int.TryParse(cell.Text,out val)
       {
        //you can have hyper link here 
        if(val > 0)
        cell.Text = "<a href='void(0);'>" + cell.Text + "</a>";
       }
      } 

    }
  }