How can i get selected rows in code behind ?
It give selected rows>0 but when i try to access
SelectedRows[0].Index then it give Input string is not in valid format.
please reply soon why this happen.
Is there another way to get selected rows if above does not work?
Hello Mypost,
I am not sure why this does not work. The code looks correct to me. Are you sure that you have the Selection Behavior enabled. Does SelectedRows[0] exist if you put a breakpoint on that line of code? Is the grid having a problem getting the index? You will need to debug the code to see what does not exist of what property is failing in that line of code. I have put together a little code snippet for you to try. Add a button to the page and handle the click event. Then past this code in there.
if (this.WebDataGrid1.Behaviors.Selection.SelectedRows.Count > 0) { if (this.WebDataGrid1.Behaviors.Selection.SelectedRows[0].Index == 0) {
} }
Then run the app and select the first row. After selecting the first row, click the button. It should stop at your break point. Step through the code and see if it makes it into the inner if statement. If it does not, then that means that the count is not greater then 0 or the index of the row is not 0. Hopefully this will help you analyze what is going on.
If this still has an issue, then I would then need to know what version of NetAdvantage you are using. There might have been a bug in the version that you are using. I tried this using the release build of 10.3.
Please let me know the outcome.
Hi Steve,
I'm getting the same problem and I think this is related to the way we the grid binds I'm binding the grid with the dataset I'm not binding it on each post back as my submit button causes the postback is it possible the gridslectionrows collection clears on postback will the count property of that collection returns correct numberbut when i try to access the row thru the indes it gives me null rowplease suggest me the right way of doing it.(my problem is that at the load time i do not have the information of Dataset as it is built on the runtime)
Ok, I think I see the problem that you are running into. If you are not going to set the datasource of the grid on every postback, then you will have to set the property EnableDataViewState to true. By default, the WebDataGrid property of EnableDataViewState is false. This means that no infomation about the rows is passed in viewstate which will now force you to set the datasource of the grid (just by setting datasource will work and an implicit binding will occur) on each and every post to the server. So, it all depends on where you want to take the hit. On the db server or over the wire as html.
So, to reiterate, the way to get this working is one of the two ways.
1) Set EnableDataViewState to True.
2) Rebind/Set the DataSource property on each postback to the server.
This is not a bug with the WebDataGrid, just the way it was architected. By default, it will try to streamline the requests back and forth to the server by not keeping the data in viewstate and recreating the row information on the server by rebinding to its datasource.