checkboxlist inside a formview databind with objectdatasource(Please somebody help me)

J

Jai

Hi,

Somebody please tell me how to bind(two way) a checkboxlist with
objectdatasource if the checkboxlist is inside a formview.....

Code of FormView is like this::---

<asp:FormView ID="FormView1" runat="server"
DataSourceID="ObjectDataSource1">
<EditItemTemplate>
<table border="0" cellpadding="0" cellspacing="0"
style="width: 100%">
<tr>
<td align="left" style="width:
100px; height: 16px;">
<asp:Label ID="lblUserName"
runat="server" AssociatedControlID="lblEditUserName" Text="User Name:"

Width="100px"></asp:Label></td>
<td align="left" style="width:
100px; height: 16px;">
<asp:Label
ID="lblEditUserName" runat="server" Text='<%# Eval("UserName")
%>'></asp:Label></td>
<td align="left" style="width:
100px; height: 16px;">
</td>
</tr>
<tr>
<td align="left" style="width:
100px">
<asp:Label
ID="lblFirstName" runat="server" AssociatedControlID="FirstName"
Text="First Name:"
Width="57px"></asp:Label></td>
<td align="left" style="width:
98px">
<asp:TextBox ID="FirstName"
runat="server" Text='<%# Bind("FirstName") %>'
CssClass="textbox"></asp:TextBox></td>
<td align="left" style="width:
100px">
</td>
</tr>
<tr>
<td align="left" style="width:
100px">
<asp:Label ID="lblLastName"
runat="server" AssociatedControlID="LastName" Text="Last Name:"

Width="57px"></asp:Label></td>
<td align="left" style="width:
98px">
<asp:TextBox ID="LastName"
runat="server" Text='<%# Bind("LastName") %>'
CssClass="textbox"></asp:TextBox></td>
<td align="left" style="width:
100px">
</td>
</tr>
<tr>
<td align="left" style="width:
100px">
<asp:Label ID="lblEmail"
runat="server" AssociatedControlID="Email" Text="Email:"

Width="57px"></asp:Label></td>
<td align="left" style="width:
98px">
<asp:TextBox ID="Email"
runat="server" Text='<%# Bind("Email") %>'
CssClass="textbox"></asp:TextBox>
<asp:RequiredFieldValidator
ID="EmailRequired" runat="server" ControlToValidate="Email"
Display="Dynamic" ErrorMessage="Email
is a required field."
ValidationGroup="modifyProfile">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="EmailFormat" runat="server" ControlToValidate="Email"
Display="Dynamic" ErrorMessage="The
email format is invalid." ValidationExpression="\S+@\S+\.\S+"

ValidationGroup="modifyProfile">*</asp:RegularExpressionValidator></td>
<td align="left" style="width:
100px">
</td>
</tr>
<tr>
<td align="left" style="width: 100px">
<asp:Label ID="lblEditOccupation"
runat="server" AssociatedControlID="cbEditOccupation"
Text="Occupation"></asp:Label></td>
<td align="left" style="width: 98px">
<asp:CheckBoxList ID="cbEditOccupation"
runat="server" AppendDataBoundItems="true" DataTextField='<%#
Bind("Occupation") %>'
DataValueField='<%#
Bind("Occupation") %>' RepeatColumns="2" RepeatDirection="Horizontal">

<asp:ListItem>Shopkeeper</asp:ListItem>

<asp:ListItem>Publisher</asp:ListItem>

<asp:ListItem>Teacher</asp:ListItem>

<asp:ListItem>Scientist</asp:ListItem>
</asp:CheckBoxList></td>
<td align="left" style="width: 100px">
</td>
</tr>

<tr>
<td align="left" style="width: 100px">
</td>
<td align="left" style="width: 100px">
<asp:ValidationSummary
ID="ValidationSummary1" runat="server" DisplayMode="List"
ValidationGroup="modifyProfile" />
<asp:ImageButton ID="btnUpdate"
runat="server" CommandName="Update"
SkinID="save" ToolTip="Save"
ValidationGroup="modifyProfile" />
<asp:ImageButton ID="btnCancel"
runat="server" CausesValidation="False" CommandName="Cancel"
SkinID="cancel" ToolTip="Cancel" />

</td>
</tr>
</table>
</EditItemTemplate>
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0"
style="width: 100%">
<tr>
<td align="left"
style="width: 100px; height: 16px;">
<asp:Label
ID="lblUserName" runat="server" AssociatedControlID="UserNameLabel"
Text="User Name:"

Width="100px"></asp:Label></td>
<td align="left"
style="width: 100px; height: 16px;">
<asp:Label
ID="UserNameLabel" runat="server" Text='<%# Bind("UserName")
%>'></asp:Label></td>
<td align="left"
style="width: 100px; height: 16px;">
</td>
</tr>
<tr>
<td align="left"
style="width: 100px">
<asp:Label
ID="lblFirstName" runat="server" AssociatedControlID="FirstNameLabel"
Text="First Name:"
Width="57px"></asp:Label></td>
<td align="left"
style="width: 100px">
<asp:Label
ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName")
%>'></asp:Label></td>
<td align="left"
style="width: 100px">
</td>
</tr>
<tr>
<td align="left"
style="width: 100px">
<asp:Label
ID="lblLastName" runat="server" AssociatedControlID="LastNameLabel"
Text="Last Name:"

Width="57px"></asp:Label></td>
<td align="left"
style="width: 100px">
<asp:Label
ID="LastNameLabel" runat="server" Text='<%# Bind("LastName")
%>'></asp:Label></td>
<td align="left"
style="width: 100px">
</td>
</tr>
<tr>
<td align="left"
style="width: 100px">
<asp:Label
ID="lblEmail" runat="server" AssociatedControlID="EmailLabel"
Text="Email:"

Width="57px"></asp:Label></td>
<td align="left"
style="width: 100px">
<asp:Label
ID="EmailLabel" runat="server" Text='<%# Bind("Email")
%>'></asp:Label></td>
<td align="left"
style="width: 100px">
</td>
</tr>
<tr>
<td align="left" style="width: 100px">
<asp:Label ID="lblOccupation"
runat="server" AssociatedControlID="cbOccupation"
Text="Occupation"></asp:Label></td>
<td align="left" style="width: 100px">
<asp:CheckBoxList ID="cbOccupation"
runat="server" DataSourceID="ObjectDataSource1"
AppendDataBoundItems="true" DataTextField='<%# Bind("Occupation") %>'
DataValueField='<%# Bind("Occupation") %>'
RepeatColumns="2"
RepeatDirection="Horizontal" Enabled="false">

<asp:ListItem>Shopkeeper</asp:ListItem>

<asp:ListItem>Publisher</asp:ListItem>

<asp:ListItem>Teacher</asp:ListItem>

<asp:ListItem>Scientist</asp:ListItem>
</asp:CheckBoxList></td>
<td align="left" style="width: 100px">
</td>
</tr>

<tr>
<td align="left" style="width: 100px">
</td>
<td align="left" style="width: 100px">
<asp:ImageButton ID="btnEdit"
runat="server" CausesValidation="False" CommandName="Edit"
SkinID="edit" ToolTip="Edit" />

</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetUser"
TypeName="Membership.MembershipManager"
UpdateMethod="EditUser">
<UpdateParameters>
<asp:parameter Name="UserName" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="Email" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="Occupation" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:profileParameter Name="UserName"
PropertyName="UserName" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

SourceCode:---------

Public Shared Function GetUser(ByVal UserName As String) As SiteUser

Dim p As SiteUser =
ProfileManager.GetUserProfileInfo(UserName)
Dim user As MembershipUser =
System.Web.Security.Membership.GetUser(UserName)

If Not (p Is Nothing) Then

If Not (p Is Nothing) Then
Return New SiteUser(p.UserName, p.FirstName,
p.LastName, p.Occupation, p.Password, p.Email, p.Question, p.Answer)
Else
Return New SiteUser(p.UserName, "", "", "", "", "",
"", "")
End If
End If

AND

Public Shared Function EditUser(ByVal UserName As String, ByVal
IsApproved As Boolean, ByVal FirstName As String, ByVal Email As
String, ByVal LastName As String, ByVal Occupation As String) As
Integer

Dim ErrorMessage As Integer = 0 'No Errors
Dim user As MembershipUser =
System.Web.Security.Membership.GetUser(UserName)
If Not IsNothing(user) Then
user.Email = Email
user.IsApproved = IsApproved
Try
System.Web.Security.Membership.UpdateUser(user)
ProfileManager.UpdateUserProfileInfo(UserName,
FirstName, LastName, Occupation)
Catch ex As Exception
ErrorMessage = 2 'Error updating user information
End Try
Else
ErrorMessage = 1 'Error finding user
End If

Return ErrorMessage

End Function

Return Nothing
End Function

One more thing is that this details are storing in the aspnet_profile
table.I had declared this occupation as:--
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Occupation" type="string"/>
</properties>
</profile>

Please help me how can i show this checkboxlist value from the profile
table and also update or insert in the profile through
checkboxlist(checkboxlist is inside a formview)

Please...Please help me....

Thanks in advance.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top