JamesAStewart
asked on
ASP.Net 2.0 Datagridview bound to arraylist - how do I make one of the columns into a dropdownlist
I am using an arraylist to populate a datagridview which is working well however, I would like to edit two of the columns.
I would like to be able to place dropdownlists into columns 2 and 3 (customerRef,ThemePreferen ce) and populate them and make the current selection visible. I can then handle any update and update the underlying profile properties information.
Any advice would be greatlly appreciated.
James
Using ASP.Net 2.0
I would like to be able to place dropdownlists into columns 2 and 3 (customerRef,ThemePreferen
Any advice would be greatlly appreciated.
James
Using ASP.Net 2.0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GridView1.DataSource = getProfiles()
GridView1.DataBind()
End Sub
Public Function getProfiles()
Dim profiles As New ArrayList
Dim userProfiles As ProfileInfoCollection
userProfiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All)
Dim userInfo As ProfileInfo
For Each userInfo In userProfiles
profiles.Add(New userProfileDetails(Profile.GetProfile(userInfo.UserName).UserName, _
Profile.GetProfile(userInfo.UserName).customerRef, _
Profile.GetProfile(userInfo.UserName).ThemePreference, _
Profile.GetProfile(userInfo.UserName).LastActivityDate))
Next
Return profiles
End Function
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" Style="position: relative" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField HeaderText="User Name" DataField="UserName"/>
<asp:BoundField HeaderText="customerRef" DataField="customerRef"/>
<asp:BoundField HeaderText="ThemePreference" DataField="ThemePreference" />
<asp:BoundField HeaderText="Last Activity" DataField="LastActivityDate" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You have already set DataTextField and DataValueField attributes for DropDownList. These are the attributes to bind it to database.
Use DataTextField="customerRef " which will show customerRef values as visible elements in the dropdownlist. Use DataValueField="customerRe f" for underlying values for each of the dropdownlist elements.
Use DataTextField="customerRef
ASKER
I maybe have not explained myself clearly enough.
The combo box is bound correctly, I need it to display (or have selected) the appropriate value (customerRef) for each row in the datagridview.
The combo box is bound correctly, I need it to display (or have selected) the appropriate value (customerRef) for each row in the datagridview.
ASKER
I've solved the problem with the following code:
Protected Sub GridView1_RowDataBound(ByV al sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
DirectCast(e.Row.FindContr ol("listCu stomersDro pDownList" ), DropDownList).SelectedValu e = DataBinder.Eval(e.Row.Data Item, "customerRef")
End If
End Sub
Protected Sub GridView1_RowDataBound(ByV
If e.Row.RowType = DataControlRowType.DataRow
DirectCast(e.Row.FindContr
End If
End Sub
ASKER
I now have a DropDownList in the DataGridView. I now need to bind the combo box to the value supplied by the DataGridView. I can get that value with:
<%# eval("customerRef") %>
Do you know how I set the combo box so that it displays the appropriate value?
Open in new window