This example is useful when you need to add new row in the gridview. Here  to can add the link URL runtime.

Add a placeholder in the HTML page.

   1: <asp:PlaceHolder ID="phGrid" runat="server"></asp:PlaceHolder>

Now create the gridview run time

   1: private void BindGrid()
   2:   {
   3:     // Create new instance of gridview
   4:       GridView gvNew = new GridView();
   5:       gvNew.ID = "ItemGrid";
   6:       gvNew.SkinID = "ListView";
   7:       gvNew.Width = 300;
   8:  
   9:       DataTable dt = Datasource();
  10:       if (dt.Columns.Count > 1)
  11:       {
  12:             // Assign RowDataBound handler. This will add link URL dynamically.
  13:           gvNew.RowDataBound += new GridViewRowEventHandler(gvNew_RowDataBound);
  14:           gvNew.DataSource = dt;
  15:           gvNew.DataBind();
  16:       }
  17:       else
  18:       {
  19:             // Some Comments
  20:       }
  21:      
  22:       phGrid.Controls.Add(gvNew);
  23:  
  24:   }
   1: protected void gvNew_RowDataBound(object sender, GridViewRowEventArgs e)
   2:  {
   3:      int random = 1;
   4:      int count = e.Row.Cells.Count;
   5:  
   6:      if (e.Row.RowType == DataControlRowType.DataRow)
   7:      {
   8:          string str = e.Row.Cells[0].Text;
   9:      }
  10:      else if (e.Row.RowType == DataControlRowType.Footer)
  11:      {
  12:  
  13:          Label lblEdit = new Label();
  14:          lblEdit.Text = "&nbsp;";
  15:          Table tbl = new Table();
  16:          tbl = (Table)e.Row.Parent;
  17:          GridViewRow myRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
  18:          DataTable dt = new DataTable();
  19:          dt = (DataTable)this.dtOCCRateList;
  20:  
  21:          for (int i = 0; i < count; i++)
  22:          {
  23:              TableCell myCell = new TableCell();
  24:              // need to create the edit hyperlink in the the footer 
  25:  
  26:              if (i == 0)
  27:              {
  28:                  // leave blank
  29:                  myCell.Controls.Add(new LiteralControl(""));
  30:              }
  31:              else
  32:              {
  33:                  // create the image and hyperlink 
  34:                  HyperLink editLink = new HyperLink();
  35:                  editLink.ID = "editLink" + random;
  36:                  
  37:                  // set the image url 
  38:                  editLink.ImageUrl = "~/library/images/ico-edit.gif";
  39:  
  40:                  // set the navigate url 
  41:                  editLink.NavigateUrl = "~/Default.aspx?Id=" + dt.Rows[0][i].ToString()
  42:                      + "&PId=" + AssetId.ToString();
  43:  
  44:                  // now add this hyperlink in the table cell
  45:                  myCell.Controls.Add(editLink);
  46:                  
  47:                  // add delete 
  48:                  HyperLink delLink = new HyperLink();
  49:                  delLink.ID = "delLink" + random;
  50:                  random++;
  51:  
  52:  
  53:                  delLink.ImageUrl = "~/Library/images/delete.gif";
  54:  
  55:                  // set the navigate url
  56:                  delLink.NavigateUrl = "~/Default.aspx?Id=" + dt.Rows[0][i].ToString()
  57:                      + "&PId=" + AssetId.ToString();
  58:  
  59:                  myCell.Controls.Add(new LiteralControl("&nbsp;"));
  60:                  myCell.Controls.Add(delLink);
  61:              }
  62:  
  63:              myRow.Cells.Add(myCell);
  64:              tbl.Rows.Add(myRow);
  65:          }
  66:      }
  67:  
  68:  }