1) need an way to implement TemplatedColumn in wdg.
proteed void Grid_InitializeRow(object sender, RowEventArgs e) { if (e.Row != null) { TemplatedColumn primary = (TemplatedColumn)e.Row.Items.FindItemByKey("name").Column; // what is an alternative for TemplatedColumn GridRecordItem cellItemPrimary = (GridRecordItem)primary.CellItems[e.Row.Index]; // is this correct?
}
2) how to implement CellItems in webdatagrid
GridField cellItemfirst = (GridField)first.CellItems[e.Row.Index];
3)find control on webdatagrid
Image secImage = (Image)cellItemSecondary.findcontrol("imgcol");
Hello Arjun,
Official documentation regarding Adding/Removing Columns, including Templated Columns to WebDataGrid could be found here:
Please notice,
When Templated columns in WebDataGrid are created programmatically in the code behind, the item template needs to be re-instantiated on each postback. More information on creating templates programmatically can be found at:
http://help.infragistics.com/Doc/ASPNET/2014.1/CLR4.0/?page=WebDataGrid_Using_Item_Template.html
You could find an online sample, regarding the use of column templates
http://ko.infragistics.com/samples/aspnet/data-grid/using-cell-and-column-templates
Reference a Cell When Creating an Item Template-official documentation
Find control in a templated column: In order to access Templated control in a WebDataGrid templated column from code behind, I suggest create a new instance of this control end iterate via the grid rows using FindControl(“”controlID”). This topic has being discussed here:
http://ko.infragistics.com/community/forums/t/45205.aspx
In general, you can only get a templated control from the corresponding cell, and not from the row. You could use column index, OR you can use its key, for example:
WebDropDown WebDropDown1= (WebDropDown1)WebDataGrid1.Rows[0].Items.FindItemByKey("ColumnKey").FindControl("WebDropDown1");
A similar topic is discussed here: http://ko.infragistics.com/community/forums/t/75727.aspx
on the deisgn i have the following code
<igtbl:Templatecolumn DataFieldName="SecondaryFileAvailable" Key="SecondaryFileAvailable"> <Header Text="Sec" /> <CellStyle HorizontalAlign="Center" /> <CellTemplate> <asp:Image ID="imgCol2" runat="server" /> </CellTemplate> </igtbl:Templatecolumn >
how do i transform this code into webdatagrid ?
I suggest you refer to the following forum thread, where both comparison between UltraWebGrid and WebDataGrid(downloadable file) and styling guides are shared.
i want to set an image to the grid cell based on its bound cell value
, how ever when setting the value
e.Row.Items.FindItemByKey("Address").Value , i get this exception A cell value can only be set for cells that are part of an UnboundField
protected void Page_Load(object sender, EventArgs e) { Grid.ClearDataSource(); Grid.DataSource = dt;
Grid.DataBind();
protected void RoutesGrid_InitializeRow(object sender, RowEventArgs e) { if (e.Row != null) { e.Row.Items.FindItemByKey("Address").Value = SetFileStatus(e.Row.Items.FindItemByKey("Address").Value.ToString()); } }
private static string SetFileStatus(string fileStatus) { switch (fileStatus) { case "Available": return "<img src='images/available.png'/>"; case "NotAvailable": return "<img src='images/notAvailable.png'/>"; default: return "<img src='images/unknown.png'/>"; } }
Please note that according to the exception that you're getting, indeed a cell value can only be set for cells that belong to UnboundField column. If you want to display an image in the grid which is not generated from the datasource, then you should use UnboundField or TemplateField column. Here is a documentation link about using Item Template: http://help.infragistics.com/doc/ASPNET/2014.1/CLR4.0/?page=WebDataGrid_Using_Item_Template.html and a link to our online samples about using UnboundField: http://ko.infragistics.com/samples/aspnet/data-grid/unbound-column
Please take a look at them and let me know if you have any further questions.
Sincerely,
Tsanna