Hi All,
I would like to apply changes to multiple columns on ItemDataBound. I am familiar with:
GridDataItem dataItem = e.Item as GridDataItem;
dataItem["Column_Name"].text = //Apply Formatting here;
Is there anyway to wildcard that? For example something like "dataItem[*].text " or do I have to do each individual column?
Thanks,
Mark
I would like to apply changes to multiple columns on ItemDataBound. I am familiar with:
GridDataItem dataItem = e.Item as GridDataItem;
dataItem["Column_Name"].text = //Apply Formatting here;
Is there anyway to wildcard that? For example something like "dataItem[*].text " or do I have to do each individual column?
Thanks,
Mark
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 16 Jan 2014, 04:01 AM
Hi Mark,
You can loop through the columns in the grid as follows:
C#:
Thanks,
Shinu
You can loop through the columns in the grid as follows:
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; foreach (GridColumn col in RadGrid1.MasterTableView.Columns) // Looping through the columns { item[col.UniqueName].Text = "Your Text"; // Each column is accessed based on its UniqueName } } }Thanks,
Shinu
0
Mark
Top achievements
Rank 1
answered on 16 Jan 2014, 04:06 AM
Shinu,
Wow, thanks! That looks like what I need!
If you have a chance could you please look at this other post of mine?
http://www.telerik.com/community/forums/aspnet-ajax/treeview/radtreeview-error-when-parent-null.aspx
Thanks,
Mark
Wow, thanks! That looks like what I need!
If you have a chance could you please look at this other post of mine?
http://www.telerik.com/community/forums/aspnet-ajax/treeview/radtreeview-error-when-parent-null.aspx
Thanks,
Mark
0
Mark
Top achievements
Rank 1
answered on 16 Jan 2014, 03:04 PM
Hi Shinu,
I just got a chance to implement that code. It looks just fine, but I see no changes. When I debug my column count is always zero, which I think is odd. This is a completely code-behind C# project for use as a SharePoint Web Part. The RadGrid and SQL Data Source are generated and added in Create Child Controls. Any thoughts?
Thanks,
Mark
I just got a chance to implement that code. It looks just fine, but I see no changes. When I debug my column count is always zero, which I think is odd. This is a completely code-behind C# project for use as a SharePoint Web Part. The RadGrid and SQL Data Source are generated and added in Create Child Controls. Any thoughts?
Thanks,
Mark
0
Mark
Top achievements
Rank 1
answered on 16 Jan 2014, 08:05 PM
That's interesting . . . if I set AutoGenerateColumns = false, and I explicitly add columns this works just fine. Does this not work with AutoGenerateColumns = true?
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2014, 03:00 AM
Hi Mark,
If you are using AutoGenerated columns then you can loop through using MasterTable's RenderColumns or AutoGeneratedColumns collection as follows:
C#:
Thanks,
Shinu
If you are using AutoGenerated columns then you can loop through using MasterTable's RenderColumns or AutoGeneratedColumns collection as follows:
C#:
foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) { //Your code }// ORforeach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns) { //Your Code }Thanks,
Shinu