mardi 6 janvier 2015

How to check the checkboxlist few items in formview

I am working with formview and I bind the data with formview. Now I have a requirement in which I have to bind a checkboxlist and want to check few checkboxes for the role which that user have assgined not all. I am trying to bind the formview with sqldatasource. Because the whole project is using the sqldatasource process. Now can anybody please tell me how can i bind the checkboxlist Checked with the roles assigned to that user


Here is the Code which I am using for bind my formview



<asp:FormView ID="ResourceFormView" runat="server" DataKeyNames="ID" DataSourceID="EmployeeSqlDataSource" Width="100%" OnItemUpdated="ResourceFormView_ItemUpdated1">
<EditItemTemplate>
<h2>Edit Resource</h2><hr />
FirstName:<br />
<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:<br />
<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
<br />
Title:<br />
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
Phone:<br />
<asp:TextBox ID="ExtensionTextBox" runat="server" Text='<%# Bind("Extension") %>' />
<br />
Email:<br />
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<br />
Department:<br />&nbsp;<asp:DropDownList ID="DeptDropDownList" runat="server" DataSourceID="DepartmentSqlDataSource" DataTextField="AD_Group_Name" DataValueField="ID" SelectedValue='<%# Bind("DepartmentID") %>'>
</asp:DropDownList>
<br />
<br />
Assgin New Role:<br />
<asp:DropDownList ID="RolesDropDownList" runat="server" DataSourceID="SqlDataSource1" DataTextField="RoleName" DataValueField="RoleId"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="SELECT [RoleId], [RoleName] FROM [vw_aspnet_Roles]"></asp:SqlDataSource>
<br />

<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
<h2>New Resource</h2><hr />
FirstName:<br />
<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:<br />
<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
<br />
Title:<br />
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
Phone:<br />
<asp:TextBox ID="ExtensionTextBox" runat="server" Text='<%# Bind("Extension") %>' />
<br />
Email:<br />
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<br />
Department:<br />
<asp:DropDownList ID="DeptDropDownList" runat="server" DataSourceID="DepartmentSqlDataSource" DataTextField="AD_Group_Name" DataValueField="ID" SelectedValue='<%# Bind("DepartmentID") %>'>
</asp:DropDownList>



<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<h2>Resource Summary</h2><hr />
<div style="text-align:right">
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" Visible='<%# User.IsInRole("Administrator") %>' />
&nbsp;|&nbsp;
<asp:LinkButton ID="StatusLinkButton" runat="server" Text='<%# BaseUtils.UserActive(Eval("Email").ToString())? "Deactivate":"Activate" %>' Visible='<%# User.IsInRole("Administrator") %>' OnClick="StatusLinkButton_Click" CommandArgument='<%#Eval("Email") %>' />

</div>
<table><tr valign="top"><td>
<br />

<%# Eval("FirstName") %> &nbsp;<%# Eval("LastName") %><br />Title:<%# Eval("Title") %>&nbsp;&nbsp;&nbsp;Extension:<%# Eval("Extension") %><br />Email:<b><%# Eval("Email") %></b><br />Department:
<b><%# BaseUtils.GetProjectDepartment(Convert.ToInt32(Eval("DepartmentID"))) %></b>
<br />Role:
<b>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlSrcRoleChk" DataTextField="RoleName" DataValueField="RoleId" RepeatDirection="Horizontal"></asp:CheckBoxList>
<asp:SqlDataSource ID="SqlSrcRoleChk" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="SELECT [RoleId], [RoleName] FROM [vw_aspnet_Roles] where userid in(select userid from aspnet_membershi"></asp:SqlDataSource>

<%--<%# GetProjectDepartment(Eval("Email").ToString()) %></b>--%>

</ItemTemplate>
</asp:FormView>


I am binding the checkbox list but please tell me how can i check only that roles which the user have assigned





Aucun commentaire:

Enregistrer un commentaire