Hi,
I have a dynamic created grid and the Grid have GridTemplateColum which contains a hyperlink. I want To format Hyperlink Text to currency. I tried below, but does not work
I have a dynamic created grid and the Grid have GridTemplateColum which contains a hyperlink. I want To format Hyperlink Text to currency. I tried below, but does not work
string Price = ((DataRowView)container.DataItem)[colname].ToString(); link.Text = String.Format("{0:C}", Price);#region Create GridTemplate column private void CreateTemplateColumn(DataTable dt, ref RadGrid rg, string FromYearMonth, string ToYearMonth) { foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "Vendor" || dc.ColumnName == "vendorID") continue; if (dc.ColumnName != "Vendor" && dc.ColumnName != "VendorID") { string ColName = dc.ColumnName; string[] DPMNameAndID = ColName.Split(';'); string DPMName = DPMNameAndID[0]; string DMPId = DPMNameAndID[1]; GridTemplateColumn templateColumn = new GridTemplateColumn(); templateColumn.ItemTemplate = new MyTemplate(ColName, FromYearMonth, ToYearMonth, DPMName, DMPId); templateColumn.SortExpression = ColName; templateColumn.HeaderText = DPMName; templateColumn.HeaderStyle.Font.Bold = true; templateColumn.FooterStyle.Font.Bold = true; templateColumn.FooterAggregateFormatString = "{0:C}"; templateColumn.DataField = ColName; templateColumn.Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum; rg.MasterTableView.Columns.Add(templateColumn); } } } private class MyTemplate : ITemplate { protected HyperLink SealeByVendorTrans; private string colname; private string _fromDate; private string _toDate; private string _DPMName; private string _DPMId; public MyTemplate(string cName, string fromDate, string toDate, string DPMName, string DPMId) { colname = cName; _fromDate = fromDate; _toDate = toDate; _DPMName = DPMName; _DPMId = DPMId; } public void InstantiateIn(System.Web.UI.Control container) { SealeByVendorTrans = new HyperLink(); SealeByVendorTrans.ID = colname; SealeByVendorTrans.DataBinding += new EventHandler(SealeByVendorTrans_DataBinding); container.Controls.Add(SealeByVendorTrans); } void SealeByVendorTrans_DataBinding(object sender, EventArgs e) { HyperLink link = (HyperLink)sender; GridDataItem container = (GridDataItem)link.NamingContainer; string Price = ((DataRowView)container.DataItem)[colname].ToString(); //txtPrice.Text = String.Format("{0:C}", price); link.Text = String.Format("{0:C}", Price); link.NavigateUrl = "HinoPartsDashBoardTransactions.aspx?type=Vendor&TransType=V&DPMName=" + _DPMName + "&DPM=" + _DPMId + "&from=" + _fromDate + "&to=" + _toDate + "&VendorID=" + ((DataRowView)container.DataItem)["VendorID"].ToString() + "&Vendor=" + ((DataRowView)container.DataItem)["Vendor"].ToString(); } } #endregion