Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdownlist asp.net 2 1

Status
Not open for further replies.

bobmmp

Programmer
Apr 22, 2002
43
US
Newbee asp.net problem. I looked at a lot of tutorials, and have not found one on this yet. Hopefully someone can help. Sorry for all the verbage. I posted this to another forum with less verbage and all I got was what are you wanting to do.

I have a dropdownlist control that is bound to a sqlDB.
I have a detailsview triggered by the onchange of the dropdowndlist. Both show on the same page. Populating the dropdownlist and triggering a record for the detailsview works great.. Problem is when I add a new record, or delete a record, I cannot get my dropdownlist to repopulated with the updated info. I used to connections to the same db because the dropdownlist combines two fields, (FirstName, Last Name as..)

The second connection for the detailsview keeps them seperate so both can be edited.

My dropdownlist is bound to a datasource called dropdownDataSource1.

The detailsview is bound to contactDataSource1.

A Details view Triggered to the onchange .. this part works great.

The codebehind:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

DetailsView1.PageIndex = DropDownList1.SelectedIndex

End Sub

I am using the standard DetailsView control. The insert/ update / delete buttons are the standard with the list control. Both are on the same rendered page.

If an Item is deleted, I would like the dropdownlist to be refreshed, or and item inserted refreshed.
I read your reply to bob and sounds like what I need to do, but all my efferts are not working. I too am used to asp and having to do everthing.

Thanks for your help and could you supply an example. BTW, the reason I use two datasources is that the data source for the dropdownlist has to combine first and last name to populated the Text value, and it also grabs the record ID for the value. The datasource for the Details view does not combine anything since each item needs to be editable.

 
Use the ItemDeleted, and ItemInserted events of the DetailsView. In those events, call your own sub that retrieves the data and rebinds your dropdown.

Jim
 
Thanks jbenson, I have tried this but not successfully, can you get me jump-started? I keep doing something wrong?
 
From the events I listed above, call something like this:
Code:
Sub RefreshDDL()
   Dim args As New System.Web.UI.DataSourceSelectArguments
   SqlDataSource1.Select(args)
   DropDownList1.DataBind()
End Sub

Jim
 
Jim, that refreshed the list which was awesome with one exception.

I tried to figure this out without bothering you, but this .net newbee is going crazy..

The dropdownlist repopulates fine, but as appends the entire list again, so all of the data is in the dropdown list twice. Regrabbing the entire list and appending it to the end of the original data in the dropdownlist.

Any way of clearing the old list first?
 
I don't have all of your code so I am not sure why it is appending anything. It should overwrite the values. You can try adding this line before you databind:
Code:
DropDownList1.Items.Clear()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top