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. Web Development
  3. ASP.NET
  4. Creating Hyperlink column in runtime

Creating Hyperlink column in runtime

Scheduled Pinned Locked Moved ASP.NET
cssdesign
6 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.
  • L Offline
    L Offline
    lijukv
    wrote on last edited by
    #1

    :) I don't want anytype of column in design time!.I tried to create Hyperlink column in runtime using the below code, but no column is shown in the grid I want to have columns this way , without any databinding. HyperLinkColumn objHyperLinkColumn = new HyperLinkColumn(); objHyperLinkColumn.HeaderText = "Liju"; grd.Columns.Add(objHyperLinkColumn);

    V 1 Reply Last reply
    0
    • L lijukv

      :) I don't want anytype of column in design time!.I tried to create Hyperlink column in runtime using the below code, but no column is shown in the grid I want to have columns this way , without any databinding. HyperLinkColumn objHyperLinkColumn = new HyperLinkColumn(); objHyperLinkColumn.HeaderText = "Liju"; grd.Columns.Add(objHyperLinkColumn);

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      take a look at following code : private void InitializeBoundColumns(DataGrid grid){ grid.AutoGenerateColumns = false; HyperLinkColumn urlCol = new HyperLinkColumn(); //the field of the DataSet which needs to be the link. urlCol.DataTextField = "Description"; //field of the DataSet which is part of our url urlCol.DataNavigateUrlField = "key"; //here we format the url... urlCol.DataNavigateUrlFormatString = servermountpath + "Uncompressed/u{0}." + extension; urlCol.Target = "_blank"; urlCol.HeaderText = "Description"; BoundColumn descCol = new BoundColumn(); descCol.DataField = "lastchange"; descCol.HeaderText = "Date (last change)"; urlCol.HeaderText = "Description"; descCol.HeaderText = "Date"; // Add the two columns to collection. grid.Columns.Add(urlCol); grid.Columns.Add(descCol); "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      L 1 Reply Last reply
      0
      • V V 0

        take a look at following code : private void InitializeBoundColumns(DataGrid grid){ grid.AutoGenerateColumns = false; HyperLinkColumn urlCol = new HyperLinkColumn(); //the field of the DataSet which needs to be the link. urlCol.DataTextField = "Description"; //field of the DataSet which is part of our url urlCol.DataNavigateUrlField = "key"; //here we format the url... urlCol.DataNavigateUrlFormatString = servermountpath + "Uncompressed/u{0}." + extension; urlCol.Target = "_blank"; urlCol.HeaderText = "Description"; BoundColumn descCol = new BoundColumn(); descCol.DataField = "lastchange"; descCol.HeaderText = "Date (last change)"; urlCol.HeaderText = "Description"; descCol.HeaderText = "Date"; // Add the two columns to collection. grid.Columns.Add(urlCol); grid.Columns.Add(descCol); "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

        L Offline
        L Offline
        lijukv
        wrote on last edited by
        #3

        Thanks for your reply previously also i tried with autogeneratecolumns = false. The recent code looks like this,but grid is not displayed. Dataset is having values ds = objDatalayerOperations.getPkeyDeta("hrmg_domainmaster","domaincode","102",cnn); grd.AutoGenerateColumns = false; HyperLinkColumn objHyperLinkColumn = new HyperLinkColumn(); objHyperLinkColumn.DataTextField = ds.Tables[0].Column[0].ColumnName.ToString(); objHyperLinkColumn.DataNavigateUrlField = ds.Tables[0].Columns[0].ColumnName.ToString(); objHyperLinkColumn.Target = "_blank"; objHyperLinkColumn.HeaderText = "Liju"; BoundColumn objBoundColumn = new BoundColumn(); objBoundColumn.DataField = ds.Tables[0].Columns[1].ColumnName.ToString(); objBoundColumn.HeaderText = "Liju2"; grd.Columns.Add(objHyperLinkColumn); grd.Columns.Add(objBoundColumn);

        V 1 Reply Last reply
        0
        • L lijukv

          Thanks for your reply previously also i tried with autogeneratecolumns = false. The recent code looks like this,but grid is not displayed. Dataset is having values ds = objDatalayerOperations.getPkeyDeta("hrmg_domainmaster","domaincode","102",cnn); grd.AutoGenerateColumns = false; HyperLinkColumn objHyperLinkColumn = new HyperLinkColumn(); objHyperLinkColumn.DataTextField = ds.Tables[0].Column[0].ColumnName.ToString(); objHyperLinkColumn.DataNavigateUrlField = ds.Tables[0].Columns[0].ColumnName.ToString(); objHyperLinkColumn.Target = "_blank"; objHyperLinkColumn.HeaderText = "Liju"; BoundColumn objBoundColumn = new BoundColumn(); objBoundColumn.DataField = ds.Tables[0].Columns[1].ColumnName.ToString(); objBoundColumn.HeaderText = "Liju2"; grd.Columns.Add(objHyperLinkColumn); grd.Columns.Add(objBoundColumn);

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #4

          is the DataGrid's Visible property set to true? Is the DataSet bound to the DataGrid? dg.DataSource : ds.Tables[0].DefaultView dg.DataBind(); "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

          L 1 Reply Last reply
          0
          • V V 0

            is the DataGrid's Visible property set to true? Is the DataSet bound to the DataGrid? dg.DataSource : ds.Tables[0].DefaultView dg.DataBind(); "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

            L Offline
            L Offline
            lijukv
            wrote on last edited by
            #5

            Thanks for your reply. That code worked and it satisfies my condition.!that's cool! :)

            V 1 Reply Last reply
            0
            • L lijukv

              Thanks for your reply. That code worked and it satisfies my condition.!that's cool! :)

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              Cp is doing strange things, so I'm replying to this post. your question was: Thanks for your solution I haven't provided that databind!.(that's why the grid was not displayed) can we do anything on grid without databinding{only in runtime} Think about a situation where we don't have to display any data from a datasource we are just creating columns-using HeaderText,Text,NavigateUrl In that case do we need databinding()? I tried without databinding , but no effect of code! what's ur comment on this! I don't really understand your question, but in order to do something with your datagrid, you have to bind it. (in Winforms it's sufficient to just set the datasource). What you do is 'format' your datagrid and then bind data to it. If you want it too show, even if no data is bound, I think you should do a DataBind with an empty dataset or something. You should find info on msdn. good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

              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