Expand/Collapse GridView rows of the same type - asp.net

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()

Related

Refresh drop down list

I have a drop down list that is populated based on the selected value of another drop down list. The main drop down list is dlJobName. It contains the list of all active jobs. The second drop down list is dlStage. This contains the distinct stage values related to the JobName. Here is the query that populates the dlStage drop down list.
SELECT DISTINCT [AnnotationDate] as Annotation_Date FROM [vw_GridviewSource] WHERE ([Name] = #Name)
In this code the AnnotationDate is not a date field but a text field. #Name is a variable equal to the selected value from the dlJobName list.
Here is my dilemma. When I make a selected_index_change event for the dlJobName, before I update the gridview that uses both of these drop down lists, I need to update the dlStage to only available values. What is happening is the dlStage list is not updated and the values in the drop down list is not available for the new JobName. Is there a way to force the query to run on the dlStage drop down list in conjunction with the selected index change event? This would cause the gridview to at least populate and not error out.
I can provide whatever additional code is necessary.
I think you have not set AutoPostBack="true" of drop down list. If Problem continues please put your HTML and cs code for proper help.
Hi maybe like other user comment you need go to property from dropdownlist, search AutoPostBack and change False for True. Don't forget clean firsr your dropdownlist
DropDownList.Items.Clear() (VB.NET)
DropDownList.Items.Clear(); (C#)
After clean your dropdownlist charge again your method to bind dropdownlist
set the property
dlJobName.AutoPostBack="true"
This will makes the SelectedIndexEvent to fired when the selected index of the main dropdown is changed.
In that selectedIndexChanged Event load the second DropdownList.
Here is an example,
http://asp-net-example.blogspot.in/2009/03/how-to-use-dropdownlist-autopostback.html
Hope your problem solved, if still exists kindly paste your snippet.

Find a specific record by field value in DevExpress VerticalGrid

Scenario: DevExpress VerticalGrid with LayoutStyle = MultiRecordView; it is bound to a System.Data.DataTable (e.g. VGridControl1.DataSource = MyDataTable).
The grid contains records of 5000 customers. We want to set the record where the CompanyName field starts with the letters 'Foo' as the focused record. Users want to be able to type a few letters of the company-name into a text-box on the form, hit a button, and then have the Vertical Grid bring the matching record into focus, without eliminating all of the other records. They want to do a "seek" not a filter. The underlying datasource would already be sorted by CompanyName.
*ADDENDUM: Also, they don't want to have to click on the sought record before they do another such search; and they want it to work even after they have scrolled the grid horizontally with the horizontal scroll bar. *
Does the Vertical Grid have any helper methods that would help with this procedure?
With the vertical grid bound to the DefaultView of a DataTable, one can iterate the DataRowViews in the DataView and examine the relevant column for a string match, returning the recordindex of the matched row, and then doing this:
vGridControl1.FocusedRecord = {record index of the matching row}

GridView Initial Editing mode?

I am writing a web application that is used for tracking and entering some everyday user data... Every day I need to enter some data for multiple users manually...
I will choose the date with the calendar, and for that date I will get DB values assigned for all users on chosen date...If there are some entries in database for that date i will display it in gridview...
Here is the look of gridview for chosen date...
USERS DATA
------------
User1 Data1
User2 Data2
User3 Data3
But, if I choose the date for which there are no entries in DB, I would like to display the gridview containg User names in each row, but I want the second column (DATA field) to be initially editable for ALL rows (the whole second column should contain textboxes for inserting values, not only selected row as in standard editable gridview mode) allowing inserting of wanted values...
I want it to look something like this
USERS DATA
----------------
User1 TextBox
User2 TextBox
User3 TextBox
My idea is to get Users list from DB and create a datatable with first column containg returned user names, and second column empty... This datatable will be datasource for gridview in which I am going to disable editing mode, and in normal (displaying) mode I am going to have TemplateField containg of textboxes bound to that datatable in second column, and labels displaying usernames in first column... When entering all values there will be SAVE button who is calling a method that will read entered values from datatable and save it to database...
Is there a better way to implement this functionality? If Templatefield textboxes are bound to datatable (as gridview datasource) textboxes entered values are going to be accessible from datable object, but Save button click causes postback, and I don't know how to preserve datatable state? Is there a better way to get wanted gridview with whole second column availibe for inserting new values?
Thank you in advance for your help & time!
Try this
http://www.highoncoding.com/Articles/219_GridView_All_Rows_in_Edit_Mode.aspx
http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
I would retrieve the full dataset using a left join in the database, and if there is no entry for a user, that user will be returned with a blank value. Something like this:
select users.user,
isnull(entries.entry,'')
from users
left join entries on users.userid = entries.userid
I think you can override the OnDataBinding (or OnDataBound) method to check and see if the second column is empty, and place the field in edit mode if it is. This way, if some users have entries but some don't, only the users with no entry will be in edit mode. Any user with an entry will be in display mode. There is a sample for this at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx.

Bound DropDownList of "unused" items plus current row item in EditItemTemplate of GridView?

I have 2 tables with unique IDs that can be mapped to each other (one table comes from a database outside of my application but has information about the same entities I'm tracking). I want to provide a UI for linking "my" records with the "other" ones, so I can store the "other" IDs in my table for the matching records. In a nutshell, the key UI element is a dropdownlist showing the available (ie, not-yet-linked) records from the "other" table.
I have a gridview for displaying "my" records in each row, plus a column showing some info from the linked record in the "other" table, if any. The data are about buildings and properties, so it might look like this:
Building1 Dallas TX Building1_Dallas_TX
Building2 Memphis TN Bldg2_Memphis_TN
Building3 Denver CO
Building4 Seattle WA
Building5 Boston MA Building5_Boston_MA
where the first 3 columns show some information from "my" table, and the last one shows the matching record from the "other" table, where the records have already been linked, else a blank where no link has been established. My actual gridview has several more columns from "my" table, but this is enough to illustrate the need.
When Edit (not shown) is clicked for a row, I want to be able to edit all 4 columns. The first 3 are textboxes; the last column should be a dropdownlist showing all of the unlinked records from the "other" table, plus an "Unassigned" option (as the first item in the list) so records can be "unlinked" or simply left unassigned, plus (for those rows that already have a link established) the linked item (it's "used" but it needs to be in there so they can continue to use it).
I can populate the dropdownlist correctly in code-behind in the gridview RowEditing event (except for the Unassigned item which I add as a ListItem in .aspx with the AppendDataBoundItems option set to true), and I can set the correct SelectedValue on the ddl's DataBound event, but on postback when I click to Update the row, the ddl has no items in it anymore (except for the Unassigned item) so the link is always cleared. If I set a link manually by directly editing my table, everything looks fine going into Edit mode -- the ddl has the correct items in it and it pre-selects the correct item, but all is lost on the Update postback. I have tried re-binding the ddl at various stages of the page cycle but clearly I don't quite understand that cycle well enough yet because I cannot figure out how to get the user-selected item to update my table.
I've also tried populating the ddl with a SqlDataSource SelectCommand, but have had no luck including the ID of currently-linked records in the other database (even though it's available in "my" table and I set it as a GridView DataKey and add it as a ControlParameter in the SelectParameters for the SqlDataSource. Without the currently-linked record in the ddl item list, I can't keep existing links.
I'll hold off sending a code sample for now -- this message is already too long! -- in hopes that the solution is obvious from what I've described... I don't think my aim is weird, but I'm open to being persuaded otherwise.
Many thanks in advance!
Chris
Ok, I'm not going into details with code because maybe you already done what I'm about to suggest.
For the last column, the drop down list, you have to execute an SQL statement to grab you the unlinked items. Use the "WHERE xx NOT IN". For the "Unassigned" option, just add an item to the list in the same code scope as above.
Next step is to handle the GridView's editing events manually. Insert, Update and Delete.
I think that way you won't have problems.

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