468,536 Members | 1,549 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,536 developers. It's quick & easy.

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

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.....

Sep 25 '06 #1
0 2197

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by I am Sam | last post: by
2 posts views Thread by P. Yanzick | last post: by
reply views Thread by avital | last post: by
2 posts views Thread by J055 | last post: by
4 posts views Thread by Victor | last post: by
6 posts views Thread by dbuchanan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.