How to add Hyperlink to ASP .NET GridView control cells dynamically at run time?

45 views Asked by At

image Grideview I want to add an hyperlink to the particular column on run time dynamically. i was able to bind Data to gridview but tried few scenario adding link to the GridView:

        DataSet ds = new DataSet();
        ds = GetData(sGridName, 0, 0);
        Session["ColumnNames"] = "";
        columnNamesAll.Clear();//Empty the list of columns so as not to duplicate or exceed limits
        if (this.sGroupID != "RSST") { gvAllTableView.Columns.Clear(); }
        
        //Loop through the dataset and add Bound Fields to Grid View
        foreach (DataColumn dc in ds.Tables[0].Columns)
        {              
            BoundField column = new BoundField();
            sName = dc.ColumnName.ToString();
            columnNamesAll.Add(sName);
            column.DataField = sName;
            if (sName == "ECD")
            {
                column.DataFormatString = "{0:M/dd/yy}";
            }
            column.SortExpression = sName;
            column.ItemStyle.Wrap = false;
            if (this.sGroupID != "RSST") { gvAllTableView.Columns.Add(column); }
        }

        Session["ColumnNames"] = columnNamesAll;


//'set the properties of the GridView Control
        gvAllTableView.AllowSorting = true;
        gvAllTableView.AutoGenerateColumns = false;
        gvAllTableView.AllowPaging = true;
        //APLN hyperlink
        gvAllTableView.DataSource = ds.Tables[0];
        gvAllTableView.SelectedIndex = Int32.Parse(Session["Selectedindex"].ToString());
        gvAllTableView.DataBind();

After binding data, this is the gridview looks like: image

Now i want to add Hyperlink only the ECD column. [Note: ECD may come in any order].

0

There are 0 answers