SteveoAtilla Posted May 2, 2005 Posted May 2, 2005 Hello all.... I have searched this forum and the 'net in general, and have not found a solution to my problem that works.... Here is the scenario: I have a datagrid on an ASPX page (vb codebehind), and I need to populate a dropdown list with a static list of items. These items do not exist in the SQL backend, but there are only five of them, so it seems simple to build a static array and bind the Datagrid to that array. Simple? Apparently not. It doesn't work. Here is what I have tried: Sub dgCurrentProposal_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgCurrentProposal.ItemDataBound If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then Dim drpPrice As DropDownList drpPrice = e.Item.FindControl("dgPricingLevel") Dim Options(5) As String Options(0) = "Bid" Options(1) = "Column 1" Options(2) = "Column 2" Options(3) = "Column 3" Options(4) = "Column 4" drpPrice.DataSource = Options drpPrice.DataBind() End If End Sub 'Item_Bound I have put the code for the dropdown in the ItemDataBound event based on advice from an article I read, but am not convinced that this is the right place for it. Any help would be greatly appreciated!!!! Also, is an event fired when a particular dropdown list item changes? Thanks, Kahuna Quote The three most important things in life: God, your family, and the Green Bay Packers -- Not necessarily in that order. Winning is not a sometime thing. You don't win once in a while, you don't do things right once in a while, you do them right all the time. Winning is a habit. Unfortunately, so is losing. -- Vincent T. Lombardi
Moderators Robby Posted May 2, 2005 Moderators Posted May 2, 2005 Are you binding/displaying the dropdown only whilst in Edit mode? I certainly hope so, anyway, create a Protected function (let's say LoadMyData) that returns your data source, then create another function to figure out which index was there prior to going into edit mode (let;s say GetMuSelectedIndex). Here's what the dd tag should look like... <asp:DropDownList id="xx" runat="server" DataSource="<%#LoadMyData%>" DataValueField="myID" DataTextField="myText" DataMember="someTable" SelectedIndex='<%# GetMySelectedIndex(Container.DataItem("myID")) %>'></asp:DropDownList> regarding the function GetMySelectedIndex: the argumnet will get you the value -in this case myID - into this function then it's up to you how you want to handle it. Quote Visit...Bassic Software
bri189a Posted May 2, 2005 Posted May 2, 2005 Rob...out of curiosity why wouldn't he bind and display in select mode? If you're saying 'Edit' mode as I think you are...see list, select item in list, see item in Edit template? Quote
Moderators Robby Posted May 2, 2005 Moderators Posted May 2, 2005 In display mode you don't need the end-user to see all the available items in a dd list, also, imagine if you had 100 rows in your datagrid and each row contained a dropdownlist with 100 items each. that would be a large download for the client. Quote Visit...Bassic Software
SteveoAtilla Posted May 3, 2005 Author Posted May 3, 2005 In display mode you don't need the end-user to see all the available items in a dd list' date=' also, imagine if you had 100 rows in your datagrid and each row contained a dropdownlist with 100 items each. that would be a large download for the client.[/quote'] Thank you both for the replies, but this application is strictly served on an intranet, and will not be used outside the building. The dropdown list has only five items, and the typical grid contains no more than 100 rows or so. I am looking for the most efficient way to accomplish this. I may go to a popup window with all pertinent fields that can be edited on that popup. There are three or four fields per row that need to be edited, so this may be a more efficient method than the text boxes and dropdown lists that I am trying to include.... I'll try to attach an image of a typical row in the grid... Thanks again for all your help. Kahuna Quote The three most important things in life: God, your family, and the Green Bay Packers -- Not necessarily in that order. Winning is not a sometime thing. You don't win once in a while, you don't do things right once in a while, you do them right all the time. Winning is a habit. Unfortunately, so is losing. -- Vincent T. Lombardi
bri189a Posted May 3, 2005 Posted May 3, 2005 Rob - while I agree with the concept I respectively don't agree that it's always the best scenerio. I have a app like his that only has a few items in the ddl, it can show up to 1000 rows and is intranet based, the only thing the user can change is the value in that ddl, everything else is read only...the ddl at most will hold 10 items...imagine it as looking at list of all 'items' and the ability to assign an item to a category and the possible categories are in the ddl... to make the user hit edit, change the value, then hit something to get out of edit mode it a lot of extra steps for the user, lot of extra code too... agreed? Of coarse we put in 'batch changes' to make life easier on the user too...but that's another subject... But like I said I do agree that in several situations it might be better to have it go to edit mode but I think its really application specific. Quote
Hyuga Posted August 26, 2005 Posted August 26, 2005 I'm recovering this thread because it's somehow related with my problem. I think I've readed the same article SteveoAtilla read before. But my problem is that I'm trying to display a Datagrid full of dropdownlists, and only one item(row) in it, and I don't know how to do it. I'm not binding nothing to the datagrid, in my test I'm only binding data to the DropDownLists, so I don't know if I can do what I want. It is possible to bind a Datagrid to an empty datasource? If it is, I can theh DataBind the datagrid and use the OnItemDataBound event to fill my dropdowns. Any idea? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.