Creating Hyperlink column in runtime
-
:) 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);
-
:) 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);
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 -
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 HendrixThanks 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);
-
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);
-
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 -
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