Update DropDownList control after inserting an item with a detailsview - asp.net

I have an update panel that includes a dropdownlist control and a detailsview control. The dropdownlist is populated by a sqldatasource control which grabs the data from a table called Places (just a list of venues). The detailsview is insert mode only and inserts places into the database table that populates the dropdownlist. I am trying to allow someone to insert a new place inside the update panel and have the dropdownlist refreshed at the same time so the user will see all places in the dropdownlist, including the one they just added with the details view. Right now, the detailsview is adding the place to the database properly but not updating the dropdownlist. If I refresh the page after adding a new place, the droplist updates with the new place. Any suggestions?

Disclaimer: This answer was posted before any code was posted in the question.
This also assumes both controls are inside the update panel.
In the event handler for Updating or Inserting for your DetailsView control, you need to add the following code:
MyDropDownList.DataBind()
And, worst case scenario, you can do this if the update panel is causing you problems. It's not the greatest performance-wise though.
Response.Redirect(Request.RawURL)

Related

Update values in gridview row after data has changed, without invoking a resort via DataBind()

A page has a gridview bound to a sqldatasource. I don't allow edits in the gridview. Most of it's columns are template fields with label controls. a formview control on the same page shows the data for the currently selected gridview row. Updates are made to the formview control. I want the gridview to reflect the updated data after it has been saved. A simple gv.DataBind() works but the data update can be involved in the gridview's sort, so if I call gv.DataBind() the updated row in gv may end up on some distant page of the grid. I would prefer that the gridview simply update any changed data in the already selected row.
What I've done so far is to have the sub that update the formview also change the text values of the labels on the selected gv row. That seems to work but does not persist. I see the changes in the gv cells, but as soon as I select another row in the gridview, the modified cells in the previously edited row go blank, for some reason.
What's a good way to do this?
Get the current page of the gridview (.PageIndex), do a DataBind(), then (re)set the page.

User inserting items in a table

I have created a simple web form on ASP.NET which includes a DropDownList with the names of all the records of a table (h. PhotoAlbums) in my database. When the user selects an album, all the items of this album (photos with tootlips) appear on the page in an order. I have carried out this by the aid of ListView control assigning a LINQ source as data source.
I would like by the selection of an album to grant the user the possibility to insert new items in the selected album at the same time and on the same page besides the appearance of the already existed items in the album. I think that I should merely use a DetailsView control and adjust this, so as to insert items. Is it though possible the DetailsView to appear after the selection of an album; not when the page is loaded initially? How?
If I understand your question,
You can Initially set the visible = "false" to the DetailsView. Then in your DropDownList OnSelectedIndexChanged method you can check the selected value and set the visible= "true". In your DropDownList you should set the property AutoPostBack="true"
Hope This Helps

find controls from dynamically created table

i wrote a function to create dynamic table in code behind on selectedindexchanged of checkbox,
that is when user will check 2 checkboxex 2 tables will be generated with textboxes,
Then on button click i want insert values of these textboxes in database,
for that i want to find textbox using findcontrol,but i could not find it,
So i called same function of table creation on page load,
but then it shows error that textbox is having duplicate id
Plz tell me solution for this.
thanks
When you create dynamic controls, you need to recreate them on every postback.
The best place to do so is in the OnInit event handler. The problem with doing it in the SelectedIndexChanged event handler of the checkbox is that on postback they will not be re-created and can't be accessed.
See this article for details, and perhaps read up on the asp.net page life cycle too.
Add a div on the page with runat="Server" and give it an ID, div1 for example.
Add the table to this div but you should always write
div1.Controls.Clear();
at the first then add the table again to the div.

Trigger update panel to refresh gridview

I have two update panels on my page. The first has a form that contains required field validators and a button that triggers the update panel and sends the info to a database. It also has a trigger for the button.
The second update panel holds a gridview that shows a few columns from the collected data. As of right now I have the gridviews update panel set to conditional and its trigger is the button that submits the first form. It's supposed to work on the click event, but the gridview isn't updating.
In other words, I want the gridview to update when I insert a new record through the form in the first update panel.
In the code behind for the button that submits the form add GridView1.DataBind(); at the end. Now changes will be reflected automatically in the gridview. Pretty neat.

RadGrid losing track of current Edit Item after insert operation on DataSource

I have a RadGrid bound to a LinqDataSource. The grid has auto generated Edit and Delete columns. It displays a simple table without any hierarchical organization.
I am taking the following steps.
Populate a RadGrid using a LinqDataSource
Click Edit on the last row of the grid
From another control on the page, update the linqdatasource and call rebind on the grid
The grid loses track of the current editing item, and opens a different item in edit mode
Please help.
If you rebind the datasource, everything will be reset. You will need to keep track of the current 'edit' item, and 're-activate' it after your rebound the datasource.
Make sure that:
All binding occcurs in the OnInit event (or after the button click is handled)
Viewstate is not disabled for the grid

Resources