Apply an ID to a GridView - asp.net

Before you say it, I'm perfectly aware that a data repeater could do it, but I'm looking for the solution using a GridView.
I'm implementing a jQuery feature and require unique ID's to be applied to individual rows in order to respond to click events in the correct manner. I can't see how you're supposed to apply values to an ID or a row.
Basically I'm looking at doing something along the lines of
$('tr').click(function() {
// get the ID of the tr and redirect the page based on that
});
EDIT: Oh, and I can do it for a row cell if that's the value I want to pass as the query string, however, I don't want to do that as it'd mean displaying a unique identifier which is something the user shouldn't be able to see.

Okay, I didn't expect to actually solve my own question. Just for reference, here it is:
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.ID = e.Row.DataItem("Issue_Key")
End If
which is placed in the RowDataBound event.

Related

How to loop gridviews for each database row?

I am developing an asp.net web form application that displays some info on separate gridviews based on parameters. The second gridview depends of the values in the first one (Salida and Llegada, they work as a time range). This works only when the data displayed on the first GV has just one row.
This is how it works:
But, is there a way to loop the same gridviews for each row stored in the database? something like this:
Or maybe there is an easier option I haven't considered.
Thanks in advance.
Ok it should be simple, first sit your gridview1 paging to fetch only view only one record, Then after you fill your gridview1 i assume that you have putten an ID either as Datakeys or what ever method you have used, the index of the row should be 0 since it's always viewing one row only. Get your id and fetch your data and bind it the second gridview2.
After that on the Gridview1_Paging event you bind your data again and the use the same method above to fetch the data for the next record.
Seems a bit clunky, but the simplest option may be to add GV1 and GV2 to a repeater. Each row of the repeater would essentially be the data source for your GV1.

Expand/Collapse GridView rows of the same type

I have a gridview with some boundfields and templatefields. My data are sales Unit-Price-Store, right now the user selects a store (from a DropDownList) and the Grid is all Unit-Price for that store.
Is there a way to make put a button next to each unit so that when the user clicks it, that row expands to include a new row for each store? IE, when I'm looking at Store 1 and I click the button I also get to see Unit-Price info for Stores 2,3,4 (but just for this item)?
I used jQuery. Basically, I tagged that column and then did an each statement. If value.innerHTML != Store $(this).closest('tr').hide(); Else assign it a function on click that looks at all 'tr' where Unit matches but Store doesn't and slideToggle()

Edit first column of GridView

I've got very dynamic GridView and I need to allow to user to edit first column of it. After he edit first column of grid it must be updated on DataBase.
Is there any ways to handle it ?
My only idea is to put some changeable element to first cell of each Row so it must be able to set / get my values for each row but can't find yet any examples of it ...
Additional info :
GridView takes data from Object data source and all columns are dynamic (yes, maybe except first, but I add it in dynamic way) and load complete DataTable... \
Currently Using jQuery+Ajax methode on dynamic button but can't disable button's PostBack so with a PostBack it just disappears and dont make the event it must to make...
Since you have dymanic columns, for each column, specify the read-only property (If a column is read-only, it may only be looked at, and not edited when in the GridView's Edit-Mode).
So, the first column of would be readonly="false" (or omit it entirely) and the other columns read-only="true".

Gridview Sorted Event

I've very small question that drives me mad :)
I've a Gridview (bind from db nothing special there) and I use small function that runs on the griviewrows and sets .Visable to false in case they don't match search criterias. It works fine but when I try to sort the grid view (by clicking on the header) all the "hidden" rows shows up again.
I tried to use the "GridView_Sorted" event in order to run on the gridview and hide again but it doesn't seem to do anything. The select statement is stored procedure so I can't use filtering expressions.
My Question is - Is there a way to run the hiding function after the sort
(as "Occurs when the hyperlink to sort a column is clicked, but after the GridView control handles the sort operation." {http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorted.aspx} suggests )
The GridView's PreRender event should do the trick.
You could just walk GridView.Rows and apply your logic there... That way it's guaranteed to occur at the right time wether the sort happens or not.
How are you binding the data?
Maybe it would help only to bind the used data (rows) to the grid, because binding not displayed data is kind of an overhead.

Get Changed Rows of GridView ASP.Net

How Can I find all the rows that has been changed in gridview. I can not use Ajax in any form
First get the contents of your grid before it was changed (such as caching the results of the original gridview datasource binding). Then go through the dataset/datatable/however you want to store it, and compare the contents with the current rows of the gridview.
There's no real efficient way to do this, no method like GridView.GetAllChangedRows(). So, what you might do instead is keep a behind the scenes List that you add to each time a row is modified (use the RowUpdated method), then clear this list when needed.
It depends upon how many columns you want to edit in a row.
If you have only one editable column in a row then you can associate a javascript method with that control which you want to modify and in that method you can get a rowid which you can save in another hidden field and in server side you can get all rows whose ids are stored in hidden field.
If you have whole row editable in that case the best approach I think you should save the original data source somewhere and also set a javascript method with rowclick event to get rowid which user selects. Then when user clicks on submit button get all rows whose row ids are stored in hidden field then compare those with same rowid in datasource. This is the best approach from my point of you.
Let me give you an example, suppose there are 1000 rows in a grid and user clicks on only 180 rows. In that case we will compare only 180 rows and wont compare rest of the rows.
Please let me know if somebody has better idea then this.

Resources