Hi, I've been scratching my head for a long time...
I have a webgrid bound to a table. One of the columns has a webcombo displaying text (using EditorControlID).
My question is how can I get the text from that specific cell, when I am inserting or updating a record ??
This is my code:
dim Cake as string = " "Cake = e.Row.Cells.FromKey("idCake").ToString
Hello 89248924,
For getting the cell's text you can obtain this through the UltraGridCell object. In the UpdateRow and AddRow server side events of the UltraWebGrid contains the RowEventArgs parameter. Within RowEventArgs you can access the cell's text or value that was updated.
I have attached a sample for demonstrating this usage.
Let me know if you have any questions with this matter. Thank you.
Yes, but how do you get the cell's text when using a WebDataGrid? I can't use FindControl because i don't always know the template control ID.
i just want to loop through the grid after i databind and look at the value of each cell but all cells are empty. How can this be?
Hello wvusaf,
To get the cell's text in each of the records that is contained in a template you can create a class inheriting ITemplate and access the cell value from DataItem. In the InstantiateIn method will run for each record. The following link can be found on an example on referencing a cell in the template column: http://help.infragistics.com/NetAdvantage/ASPNET/2011.1/CLR4.0/?page=WebDataGrid_Refrence_a_Cell_When_Creating_an_Item_Template.html.
Also I have attached an updated sample when applying ItemTemplate in the WebDataGrid.
Yes, that example will work. however, i don't always know the template ID for all the cells.
i'm looping through every cell in the grid. also, sometimes the columns are BoundFields which have no template. in this case, there is a text value for the cell but that value is different than what the formatted value will be.
as an example, say i have a string value of "16.32334553324". when formatted to 2 decimal places the end value as displayed on the web page is "16.32", which is quite shorter. this makes a difference because i'm trying to set the column width dynamically based on the width of the cell's content, but you can see here, it will not work correctly.
the whole reason i'm trying to set the column width dynamically is because the webdatagrid does a terrible job of it on its own.
To get the value in the cell can be done by returning the Label's text after calling the FindControl method from GridRecordItem. In the sample provided can be applied in Page Load to return the Label by passing in "TemplateLabel" as the ID:
foreach (GridRecord gridRecord in this.WebDataGrid1.Rows){ GridRecordItem gridRecordItem = gridRecord.Items[0]; Label label = (Label)gridRecordItem.FindControl("TemplateLabel"); string text = label.Text;}
Duane,
I'm using NetAdvantage ASP.NET 2012 Vol. 1, 3.5 Framework. There is no UltraWebGrid available.
But, i modified your project and took out the combo and ultragrid and then changed the asembly version in the web.config so i could run it with the WebDataGrid.
But still, after you set the datasource in the Pre_Init event, if you loop through the rows in the Page_Load event you'll see that all cells have empty text and a value of null.