That means the job title belongs to which department.
So I want to databound all department name from table "Department".
For New Record, it will display all department name.
In Edit Mode, if user already check before, the checkbox will automatically check. How can i use OnDataBound in code behind to databound the checkbox by RadGrid DataKeyNames "ID" ?
It returns the following error when i click Add New/Edit:
Server Error in '/LRDB' Application.
The DataSourceID of 'CheckBoxList_Dept' must be the ID of a control of type IDataSource. A control with ID 'LDS_Dept' could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: The DataSourceID of 'CheckBoxList_Dept' must be the ID of a control of type IDataSource. A control with ID 'LDS_Dept' could not be found.
Source Error:
|
My code as follows:
<%@ Page Title="" Language="VB" MasterPageFile="~/LRDB.master" AutoEventWireup="false" CodeFile="Admin_dictionary_JobTitle.aspx.vb" Inherits="Admin_Admin_dictionary_JobTitle" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<br />
<strong><span class="style4">Job Title</span><br /> </strong><br />
<telerik:RadCodeBlock ID="RadCodeBlock8" runat="server">
<script type="text/javascript">
function RowDblClick(sender, eventArgs) {
sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
}
function conformbox() {
var con = confirm("Are you sure want to delete?");
if (con == true) {
return true;
}
else {
return false;
}
}
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel8" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="RadGrid_JobTitle" runat="server" CellSpacing="0"
DataSourceID="LDS_JobTitle" width="800" PageSize="15"
GridLines="None" style="margin-top: 0px" AllowFilteringByColumn="True"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
ShowStatusBar="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="false"
AllowAutomaticUpdates="True">
<GroupingSettings CaseSensitive="false" />
<MasterTableView AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="LDS_JobTitle"
AllowFilteringByColumn="False" AllowPaging="False"
CommandItemDisplay="Top" OverrideDataSourceControlSorting="true" >
<CommandItemSettings ExportToPdfText="Export to PDF" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
Visible="True">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
Visible="True">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderStyle-Width="50">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="ID"
FilterControlAltText="Filter ID column" HeaderText="ID"
SortExpression="ID" UniqueName="ID" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Job_Title_ShortName"
FilterControlAltText="Filter Job_Title_ShortName column" HeaderText="Short Name"
SortExpression="Job_Title_ShortName" UniqueName="Job_Title_ShortName" HeaderStyle-Width="200">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Job_Title"
FilterControlAltText="Filter Job_Title column" HeaderText="Long Name"
SortExpression="Job_Title" UniqueName="Job_Title">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<EditColumn FilterControlAltText="Filter EditCommandColumn1 column"
UniqueName="EditCommandColumn1">
</EditColumn>
<FormTemplate>
<table id="Table2" cellspacing="2" cellpadding="1" width="50%" border="1" rules="none"
style="border-collapse: collapse;">
<tr class="EditFormHeader">
<td style="width:150px">
<asp:Label ID="lb" Text="Short Name" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="tb_job_title_ShortName" runat="server" Text='<%# Bind("job_title_ShortName") %>' TabIndex="2"></asp:TextBox>
</td>
</tr>
<tr >
<td >
<asp:Label ID="Label2" Text="Long Name" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="tb_job_title" runat="server" Text='<%# Bind("job_title") %>' TabIndex="2"></asp:TextBox>
</td>
</tr>
<tr >
<td >
<asp:Label ID="Label1" Text="Department" runat="server"></asp:Label>
</td>
<td>
<asp:CheckBoxList ID="CheckBoxList_Dept" runat="server"
AutoPostBack="True"
OnDataBound="CheckBoxList_Dept_DataBound" DataSourceID="LDS_Dept"
DataTextField="Department" DataValueField="DeptID" TabIndex="1"
RepeatColumns="8" >
</asp:CheckBoxList>
<asp:LinqDataSource ID="LDS_Dept" runat="server"
ContextTypeName="dcLRDBDataContext" EntityTypeName=""
TableName="db_Departments">
</asp:LinqDataSource>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' >
</asp:Button>
<asp:Button ID="btnDelete" Text="Delete" runat="server" CausesValidation="False"
CommandName="Delete" OnClientClick="return conformbox();" ></asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox" />
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox" />
<FilterMenu EnableImageSprites="False">
</FilterMenu>
</telerik:RadGrid>
<asp:LinqDataSource ID="LDS_JobTitle"
runat="server" ContextTypeName="dcLRDBDataContext" EntityTypeName=""
TableName="db_Dictionary_Job_Titles">
</asp:LinqDataSource>
</asp:Content>
Code Behind:
Imports SystemImports System.IOImports Telerik.Web.UIImports System.Web.UIImports Telerik.Web.UI.AsyncUploadImports System.Runtime.Serialization.JsonImports System.Web.ServicesImports System.Runtime.SerializationImports System.Collections.GenericImports System.DrawingPartial Class Admin_Admin_dictionary_JobTitle Inherits System.Web.UI.Page Protected Sub RadGrid_JobTitle_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid_JobTitle.ItemCommand RadGrid_JobTitle.MasterTableView.ClearEditItems() If e.CommandName = RadGrid.InitInsertCommandName Then 'Click Add New Record button Dim editColumn As GridEditCommandColumn = CType(RadGrid_JobTitle.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn) editColumn.Visible = False ElseIf (e.CommandName = RadGrid.RebindGridCommandName AndAlso e.Item.OwnerTableView.IsItemInserted) Then e.Canceled = True Else Dim editColumn As GridEditCommandColumn = CType(RadGrid_JobTitle.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn) If Not editColumn.Visible Then 'Click Cancel button (both Insert and Update mode) editColumn.Visible = True End If Dim txt_job_title_ShortName As TextBox = DirectCast(e.Item.FindControl("tb_job_title_ShortName"), TextBox) Dim txt_job_title As TextBox = DirectCast(e.Item.FindControl("tb_job_title"), TextBox) Dim dc As New dcLRDBDataContext If e.CommandName = "PerformInsert" Then Dim newRecord1 As New db_Dictionary_Job_Title dc.db_Dictionary_Job_Titles.InsertOnSubmit(newRecord1) newRecord1.Job_Title_shortname = txt_job_title_ShortName.Text newRecord1.Job_Title = txt_job_title.Text newRecord1.LastUpdateDate = DateTime.Now newRecord1.LastUpdateBy = HttpContext.Current.Session("UserID") dc.SubmitChanges() RadGrid_JobTitle.MasterTableView.ClearEditItems() RadGrid_JobTitle.DataBind() ElseIf e.CommandName = "Update" Then Dim lid As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID") Dim rec = (From p In dc.db_Dictionary_Job_Titles Where p.ID = lid).FirstOrDefault If Not rec Is Nothing Then rec.Job_Title_shortname = txt_job_title_ShortName.Text rec.Job_Title = txt_job_title.Text rec.LastUpdateBy = HttpContext.Current.Session("UserID") rec.LastUpdateDate = DateTime.Now dc.SubmitChanges() End If RadGrid_JobTitle.MasterTableView.ClearEditItems() RadGrid_JobTitle.DataBind() ElseIf e.CommandName = "Delete" Then Dim lid As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID") Dim chk_rec = (From a In dc.db_Competency_Lists Where a.Job_Title_ID = lid).Count If chk_rec > 0 Then Page.ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox", "alert('Cannot delete because this dictionary had been used.');", True) Else Dim chk_rec2 = (From a In dc.db_Employee_Details Where a.Job_Title_ID = lid).Count If chk_rec2 > 0 Then Page.ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox", "alert('Cannot delete because this dictionary had been used.');", True) Else Dim rec2 = (From p In dc.db_Dictionary_Job_Titles Where p.ID = lid).FirstOrDefault If Not IsNothing(rec2) Then dc.db_Dictionary_Job_Titles.DeleteOnSubmit(rec2) dc.SubmitChanges() End If End If End If RadGrid_JobTitle.MasterTableView.ClearEditItems() RadGrid_JobTitle.DataBind() End If dc.Dispose() End If End Sub Protected Sub CheckBoxList_Dept_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) End SubEnd ClassThanks