Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Dynamic add html in GridView by c# code????

How to Dynamic add html in GridView by c# code????

Scheduled Pinned Locked Moved C#
questioncsharphtmlhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mimimimilaw
    wrote on last edited by
    #1

    Dear Friend, I am working on GridView in c#. Getting a problem on dynamic add html in a GridView Columns. How can I make a dynamic template by coding??? Many thanks. DataTable dt = new DataTable(); dt.Columns.Add("Id", Type.GetType("System.Int32")); dt.Columns.Add("Detail", Type.GetType("System.String")); dr = dt.NewRow(); dr["Id"] = id; dr["Detail"] = "<a href='home.aspx#" + id + "' >Detail</a>"; dt.Rows.Add(dr); gridView.DataSource = dt; gridView.DataBind();

    R 1 Reply Last reply
    0
    • M mimimimilaw

      Dear Friend, I am working on GridView in c#. Getting a problem on dynamic add html in a GridView Columns. How can I make a dynamic template by coding??? Many thanks. DataTable dt = new DataTable(); dt.Columns.Add("Id", Type.GetType("System.Int32")); dt.Columns.Add("Detail", Type.GetType("System.String")); dr = dt.NewRow(); dr["Id"] = id; dr["Detail"] = "<a href='home.aspx#" + id + "' >Detail</a>"; dt.Rows.Add(dr); gridView.DataSource = dt; gridView.DataBind();

      R Offline
      R Offline
      Rod Kemp
      wrote on last edited by
      #2

      Use a HyperLinkField;

      HyperLinkField detailLink = new HyperLinkField();
      detailLink.NavigateUrl = string.Format("home.aspx#{0}", id);
      detailLink.Text = "Detail";
      gridView.Columns.Add(detailLink);

      You will also need to set the AutoGenerateColumns to false and create a BoundField for the id column.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups