Hi,
Somebody please tell me how to bind(two way) a checkboxlist with
objectdatasourc e if the checkboxlist is inside a formview.....
Code of FormView is like this::---
<asp:FormView ID="FormView1" runat="server"
DataSourceID="O bjectDataSource 1">
<EditItemTempla te>
<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" AssociatedContr olID="lblEditUs erName" Text="User Name:"
Width="100px"></asp:Label></td>
<td align="left" style="width:
100px; height: 16px;">
<asp:Label
ID="lblEditUser Name" 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="lblFirstNam e" runat="server" AssociatedContr olID="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="textb ox"></asp:TextBox></td>
<td align="left" style="width:
100px">
</td>
</tr>
<tr>
<td align="left" style="width:
100px">
<asp:Label ID="lblLastName "
runat="server" AssociatedContr olID="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="textb ox"></asp:TextBox></td>
<td align="left" style="width:
100px">
</td>
</tr>
<tr>
<td align="left" style="width:
100px">
<asp:Label ID="lblEmail"
runat="server" AssociatedContr olID="Email" Text="Email:"
Width="57px"></asp:Label></td>
<td align="left" style="width:
98px">
<asp:TextBox ID="Email"
runat="server" Text='<%# Bind("Email") %>'
CssClass="textb ox"></asp:TextBox>
<asp:RequiredFi eldValidator
ID="EmailRequir ed" runat="server" ControlToValida te="Email"
Display="Dynami c" ErrorMessage="E mail
is a required field."
ValidationGroup ="modifyProfile ">*</asp:RequiredFie ldValidator>
<asp:RegularExp ressionValidato r
ID="EmailFormat " runat="server" ControlToValida te="Email"
Display="Dynami c" ErrorMessage="T he
email format is invalid." ValidationExpre ssion="\S+@\S+\ .\S+"
ValidationGroup ="modifyProfile ">*</asp:RegularExpr essionValidator ></td>
<td align="left" style="width:
100px">
</td>
</tr>
<tr>
<td align="left" style="width: 100px">
<asp:Label ID="lblEditOccu pation"
runat="server" AssociatedContr olID="cbEditOcc upation"
Text="Occupatio n"></asp:Label></td>
<td align="left" style="width: 98px">
<asp:CheckBoxLi st ID="cbEditOccup ation"
runat="server" AppendDataBound Items="true" DataTextField=' <%#
Bind("Occupatio n") %>'
DataValueField= '<%#
Bind("Occupatio n") %>' RepeatColumns=" 2" RepeatDirection ="Horizontal ">
<asp:ListItem>S hopkeeper</asp:ListItem>
<asp:ListItem>P ublisher</asp:ListItem>
<asp:ListItem>T eacher</asp:ListItem>
<asp:ListItem>S cientist</asp:ListItem>
</asp:CheckBoxLis t></td>
<td align="left" style="width: 100px">
</td>
</tr>
<tr>
<td align="left" style="width: 100px">
</td>
<td align="left" style="width: 100px">
<asp:Validation Summary
ID="ValidationS ummary1" runat="server" DisplayMode="Li st"
ValidationGroup ="modifyProfile " />
<asp:ImageButto n ID="btnUpdate"
runat="server" CommandName="Up date"
SkinID="save" ToolTip="Save"
ValidationGroup ="modifyProfile " />
<asp:ImageButto n ID="btnCancel"
runat="server" CausesValidatio n="False" CommandName="Ca ncel"
SkinID="cancel" ToolTip="Cancel " />
</td>
</tr>
</table>
</EditItemTemplat e>
<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" AssociatedContr olID="UserNameL abel"
Text="User Name:"
Width="100px"></asp:Label></td>
<td align="left"
style="width: 100px; height: 16px;">
<asp:Label
ID="UserNameLab el" 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="lblFirstNam e" runat="server" AssociatedContr olID="FirstName Label"
Text="First Name:"
Width="57px"></asp:Label></td>
<td align="left"
style="width: 100px">
<asp:Label
ID="FirstNameLa bel" 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" AssociatedContr olID="LastNameL abel"
Text="Last Name:"
Width="57px"></asp:Label></td>
<td align="left"
style="width: 100px">
<asp:Label
ID="LastNameLab el" 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" AssociatedContr olID="EmailLabe l"
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="lblOccupati on"
runat="server" AssociatedContr olID="cbOccupat ion"
Text="Occupatio n"></asp:Label></td>
<td align="left" style="width: 100px">
<asp:CheckBoxLi st ID="cbOccupatio n"
runat="server" DataSourceID="O bjectDataSource 1"
AppendDataBound Items="true" DataTextField=' <%# Bind("Occupatio n") %>'
DataValueField= '<%# Bind("Occupatio n") %>'
RepeatColumns=" 2"
RepeatDirection ="Horizontal " Enabled="false" >
<asp:ListItem>S hopkeeper</asp:ListItem>
<asp:ListItem>P ublisher</asp:ListItem>
<asp:ListItem>T eacher</asp:ListItem>
<asp:ListItem>S cientist</asp:ListItem>
</asp:CheckBoxLis t></td>
<td align="left" style="width: 100px">
</td>
</tr>
<tr>
<td align="left" style="width: 100px">
</td>
<td align="left" style="width: 100px">
<asp:ImageButto n ID="btnEdit"
runat="server" CausesValidatio n="False" CommandName="Ed it"
SkinID="edit" ToolTip="Edit" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
SelectMethod="G etUser"
TypeName="Membe rship.Membershi pManager"
UpdateMethod="E ditUser">
<UpdateParamete rs>
<asp:Paramete r Name="UserName" Type="String" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="Email" Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="Occupatio n" Type="String" />
</UpdateParameter s>
<SelectParamete rs>
<asp:ProfilePar ameter Name="UserName"
PropertyName="U serName" Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>
SourceCode:---------
Public Shared Function GetUser(ByVal UserName As String) As SiteUser
Dim p As SiteUser =
ProfileManager. GetUserProfileI nfo(UserName)
Dim user As MembershipUser =
System.Web.Secu rity.Membership .GetUser(UserNa me)
If Not (p Is Nothing) Then
If Not (p Is Nothing) Then
Return New SiteUser(p.User Name, p.FirstName,
p.LastName, p.Occupation, p.Password, p.Email, p.Question, p.Answer)
Else
Return New SiteUser(p.User Name, "", "", "", "", "",
"", "")
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.Secu rity.Membership .GetUser(UserNa me)
If Not IsNothing(user) Then
user.Email = Email
user.IsApproved = IsApproved
Try
System.Web.Secu rity.Membership .UpdateUser(use r)
ProfileManager. UpdateUserProfi leInfo(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="Occupatio n" 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(ch eckboxlist is inside a formview)
Please...Please help me....
Thanks in advance.....