How can I get value of a GridView control in Eval? - c#

I have a GridView ItemTemplate column in which I have two controls .. DropDownList and a LinkButton. I want to show the selectedItem of DropDownon LinkButton. I am easily able to do so through code behind from selected index changed event. But the problem is that I am not able to maintain the state of the linkbutton when I add a new row on a button click. (because it is not bound to any datasource)
Anyways, can I bind LinkButton with the selected Value of the Dropdown? Something like:
Eval(drp1.SelectedItem.ToString())

If DropDownList is databound from another table, you can add the "Text Value" of the DropDownList from database and display its value to LinkButton.
For example:
If I've a table holds countries and DropDownList to display them, and I've another table storing country Id. In your scenario you can add Inner Join to your select query and display country name in LinkButton text.

Related

Gridview dropdownlist must show item in dataset as its selected item

i have a dropdownlist in a column in a gridview. This dropdwon already had two items in it i.e Close/Open. What i require is that I bind the gridview to a dataset, all i want is for the dropdown to show the value that is in the dataset.(open or close)
I got the answer. Its a bit of an work around. You cannot directly bind the gridview dropdownlist to the dataset column. What I did instead was, I bound the Dataset column to a hiddenfield and then in Rowdatabound event i assigned the dropdown.selectedvalue to the hiddenfield.value.
Works Perfectly...Thanks everyone.

Devexpress MVC GridView ComboBox Column Type DataSource

How to alternate DataSource in ComboBox Column inside Devexpress GridView by selecting value in other ComboBox column in same row.
It is something like cascading comboboxes but in Grid view (but in grid comboboxses don't have CallbackRouteValues property)
Grid has two comboboxes and if user selects one value in frst the second combobox must change datasource by function that takes id as parameter from first selected combobox
You want to use a LookUpEdit instead of ComboBox when you are using a datasource, then you can use the QueryPopUp event to set a filter to, or change your datasource.
Note that when you change the datasource for the LookUpEdit, the result in the grid might not look what you expected. To remedy that, you want to clear your filter in the QueryCloseUp event.

How can I retain a GridViewRow value?

My GridView is loaded with data from my database in a DataSet, which corresponds to Labels inside the GridView.
When users click the Select button on a GridViewRow, the button fills a TextBox outside the GridView from the selected row's column value.
After editing values in the TextBox outside my GridView, the user can click a button to move the new value from the TextBox back to the GridView (but not to the database).
My problem is: when I select the next row and do the same action, it clear the previous newly-added row data. It doesn't retain the previous row data.
I know it can be done by ViewState or Session, but it didn't work for me.
check for if(! ispostback) before filling data back to your grid. i am assuming that on click of select (Edit) button your page post back and then it fills value in textbox for edit and same time its refilling data in grid control also. so before filling value in grid control make sure its not postback.

binding the gridview view .....which is in edit template of another

I am having a gridview control and in the edit template of the gridview control., inside the edit template I need another grid view control., I am having a bound field in the second gridview which always binds to the selected value in the gridview 1 .,
So can somebody tell me in which event and all i have to do the databind for the gridview 2.
I am having an sqldatasource for the gridview2.
Thanks
i think the event you are looking for is "row_command" of your main gridview. in row_command event, you can get your value from the row that you selected, then find your gridview inside your row, and give its datasource.
i cant test it now, but should be something like this
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = MainGridView.Rows[index];
Gridview dv = row.FindControl(“yourGridViewId”);
dv.DataSource = yourdatasource;

How do I dynamically populate a gridview based on the selected row of another gridview?

Suppose I have a e-shop web app. I have a product categories table in my database that populates a gridview using sqldatasource.
I want to be able to click on the select hyperlink on a row and use that event to populate ANOTHER gridview based on the ID of the product category that is clicked. E.g say the 'CDs' row is clicked, another gridview shows all the different CDs.
As a result, I need the select(sql) statement for the second table to be dynamic based on what the user clicks.
Has anyone done anything like this before?
Any help would be greatly appreciated,
Mark
It should be very easy. The key is to use SelectedValue of first Gridview to be used as a parameter to the query to populate second gridview.
Here is a sample: Master/Detail GridView
The sample show GV and DetailsView but in your case you replace DV with another GV.

Categories