how to get selected row value at server side
i uase ultrawebgrid and i want selected row value on one button click
UltraWebGrid1.DisplayLayout.SelectedRows; -> Gives you a collection of selected rows (can be more than one)
UltraWebGrid1.DisplayLayout.ActiveRow; -> Gives you te actual active row. This method always returns just one row.
i used that one but it's wan't wrok for me
can u give me some expamle of that coding
and any properties i have to set for that webgrid
with the ActiveRow you can get the row that has the focus at that moment. The only 'value' you can get there would be the row's index. If you want to get some cell's value within that row, you can have access either with the cell's index or with the cell's key like this:
UltraWebGrid1.DisplayLayout.ActiveRow.Cells[0].Value;
UltraWebGrid1.DisplayLayout.ActiveRow.Cells.FromKey("Column's_Key").Value;
i used some thing like this way , but it' give me an erroe
'Label1.Text = UltraWebGrid1.DisplayLayout.ActiveRow.Cells.FromKey("FirstName").Value
Label1.Text = UltraWebGrid1.DisplayLayout.ActiveRow.Cells(1).Value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error:
Line 13: Dim row As UltraGridRow = UltraWebGrid1.DisplayLayout.ActiveRow Line 14: 'Label1.Text = UltraWebGrid1.DisplayLayout.ActiveRow.Cells.FromKey("FirstName").Value Line 15: Label1.Text = UltraWebGrid1.DisplayLayout.ActiveRow.Cells(1).Value Line 16: End Sub Line 17:
Maybe there's no active row at that point. If you're not selecting any row before triggering that event you'd probable get this kind of exception.. I suggest you place a breakpoint when you try to get the active row to see if it return an actual row.
You can try something like
UltraGridRow row = grid.DIsplayLayout.ActiveRow;
if(row != null)
{
//and here get the value from the cell
}
Here is heml code
<bands>
<igtbl:UltraGridBand>
<Columns>
<igtbl:UltraGridColumn Type="Button">
<header caption="Select">
</header>
</igtbl:UltraGridColumn>
IsBound="True" Key="FirstName">
<header caption="FirstName">
<rowlayoutcolumninfo originx="1" />
<footer>
</footer>
IsBound="True" Key="LastName">
<header caption="LastName">
<rowlayoutcolumninfo originx="2" />
</Columns>
<addnewrow view="NotSet" visible="NotSet">
</addnewrow>
</igtbl:UltraGridBand>
</bands>
I don't seem to get what the problem could be.. If you have at least one row selected it should be already in the SelectedRows colection.. Have you tried with the ActiveRow too? As I told you this one returns the single row that has the focus at that moment. Althog by the code you provided, I also do not see the functionality you're trying to achieve. Maybe you could try to explain a little bit more your scenario and specify if there's any other control in te equation.
Hi all
Thanks for all these help
InitializeDataSource event it's wroks perfectly
i aprriciate all help from you guys
Thanks
Hello,
I think the problem here is that databinding occurs prior to executing the postback event handler that gets the selected rows. The problem is that databinding essentially clears the selected rows collections (empties the grid and rebinds again).
You can try moving the code databinding the grid from Page_Load to the grid InitializeDataSource event. Also, you can check the lifecycle of the page.
I believe a very similar thread with a similar problem is discussed (SelectedRows.Count = 0 even when rows are selected) here:
http://forums.infragistics.com/forums/p/11104/42129.aspx