Can I modify the Display text value of DataField value of GridBoundColumn ?
I have "4-code"
and need to display just "Code"
Seems like there should be in-house property to handle this rather than in the data retrieval or the subsequent JavaScript display.
I have "4-code"
and need to display just "Code"
Seems like there should be in-house property to handle this rather than in the data retrieval or the subsequent JavaScript display.
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 13 Mar 2014, 09:08 AM
Hi Dan,
I assume that you want to change the text of the GridBoundColumn. Please have a look into the following code snippet.
C#:
Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
I assume that you want to change the text of the GridBoundColumn. Please have a look into the following code snippet.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e){ if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; if (item["Cityname"].Text == "4-Code") { item["Cityname"].Text = "Code"; } }}Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
0
Dan
Top achievements
Rank 1
answered on 13 Mar 2014, 05:21 PM
Yes and no, using code behind and with Databound event was a direction I was gonna go but I was hoping for some radgrid attribute or possibly some front-end (jQuery) code sample:
I am using:
protected void gvwMenuDelayCodes_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (item["dlcCode"].Text.IndexOf('-') > 0)
{
string[] codeParts = item["dlcCode"].Text.Split('-');
try
{
Convert.ToInt16(codeParts[0].Trim());
item["dlcCode"].Text = codeParts[1];
}
catch { }
}
}
}
I am using:
protected void gvwMenuDelayCodes_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (item["dlcCode"].Text.IndexOf('-') > 0)
{
string[] codeParts = item["dlcCode"].Text.Split('-');
try
{
Convert.ToInt16(codeParts[0].Trim());
item["dlcCode"].Text = codeParts[1];
}
catch { }
}
}
}
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Mar 2014, 08:44 AM
Hi Dan,
Please try the following JavaScript to achieve your scenario.
JavaScript:
Thanks,
Princy.
Please try the following JavaScript to achieve your scenario.
JavaScript:
<script type="text/javascript"> function pageLoad() { var grid = $find("<%=RadGrid1.ClientID %>"); var MasterTable = grid.get_masterTableView(); var Rows = MasterTable.get_dataItems(); for (var i = 0; i < Rows.length; i++) { var row = Rows[i]; var text = row.get_cell("Cityname").innerText; if (text.indexOf('-') != -1) { row._element.outerText = text.split("-")[1]; } } }</script>Thanks,
Princy.
0
Dan
Top achievements
Rank 1
answered on 14 Mar 2014, 10:58 PM
Thanks Princy:
Worked pretty good after minor corrections:
Worked pretty good after minor corrections:
function pageLoad() { var grid = $find("<%=gvwMenuDelayCodes.ClientID %>"); if (grid != null) { var MasterTable = grid.get_masterTableView(); var Rows = MasterTable.get_dataItems(); for (var i = 0; i < Rows.length; i++) { var row = Rows[i]; var text = row.get_cell("dlcCode").innerText; if (text.indexOf('-') > 0) { row.get_cell("dlcCode").innerText = text.split("-")[1]; } } } }