for the new admin. function of my application, there is a gridview to show records in database.
there is a textbox to let user input staff name and then click "search" button. I want to show the search result in Listbox (show similar staff name). when user click on the name, it will automatically insert into db and then refresh the gridview.
How can I databind the listbox based on the textbox ? and how can i insert the value when user click listbox ? Thanks.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ITAlert.aspx.vb" Inherits="DepartmentManager_ITAlert" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="width: 500px; margin-left: auto; margin-right: auto;">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<asp:Label ID="Label1" runat="server" Text="Staffs to get the email alert:" Font-Bold="true"></asp:Label>
<br /><br />
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" allowpaging="true"
AutoGenerateColumns="False" DataSourceID="LDS" GridLines="None" pagesize="20"
AllowAutomaticDeletes="True" Style="border: 0; outline: none;"
OnDeleteCommand="RadGrid1_DeleteCommand"
>
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView DataSourceID="LDS" DataKeyNames="ID">
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="DisplayName" FilterControlAltText="Filter Name column"
HeaderText="Staff Name" ReadOnly="True" SortExpression="DisplayName" UniqueName="DisplayName">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn ConfirmText="Delete this record?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" Text="Delete" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid>
<asp:LinqDataSource ID="LDS" runat="server" ContextTypeName="DataContext"
OrderBy="DisplayName" Select="new (ID, DisplayName)" TableName="v_EmailAlerts"
Where="Type == 4">
<WhereParameters>
<asp:QueryStringParameter Name="CID" QueryStringField="CID"
Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<br />
<br />
<asp:TextBox runat="server" ID="tb_staffname">
</asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_click"/>
<telerik:RadListBox runat="server" ID="RadListBox_staff" Height="300px" Width="230px"
AllowTransfer="false"
AutoPostBack="false"
style="top: 0px; left: 0px" DataSourceID="LDS_staff"
DataTextField="displayname" DataValueField="sid" >
</telerik:RadListBox>
<asp:LinqDataSource ID="LDS_staff" runat="server" ContextTypeName="dcHRISDataContext"
OrderBy="DisplayName" Select="new (SID, DisplayName)" TableName="vHRIS_StaffDBs"
Where="Lefe == False and SID is nothing">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
Code Behind (with proposed listbox databind function) :
Imports Telerik.Web.UI
Partial Class DepartmentManager_ITAlert
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.DeleteCommand
Dim AlertID = DirectCast((DirectCast(e.Item, GridDataItem)).GetDataKeyValue("ID"), Integer)
'retrive entity form the Db
Dim dc As New DataContext
Dim rec = (From a In dc.EmailAlerts Where a.id = AlertID).firstordefault
If rec IsNot Nothing Then
dc.HRIS_EmailAlerts.DeleteOnSubmit(rec)
dc.SubmitChanges()
End If
End Sub
Protected Sub btnSearch_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim sname As String = ""
sname = tb_staffname.text
If sname <> "" Then
Dim dc As New dcHRISDataContext
Dim rec = (From a In dc.vHRIS_StaffDBs Where a.Lefe = False _
And (x >= x.DisplayName.Matches(sname)) Select a.SID, a.DisplayName Order By DisplayName).ToList
RadListBox_staff.DataTextField = "DisplayName"
RadListBox_staff.DataValueField = "SID"
RadListBox_staff.DataSource = dt
RadListBox_staff.DataBind()
End If
End Sub
End Class
moreover, it display error for the linq of searching function
the error msg as follows:
Compiler Error Message: BC36610: Name 'x' is either not declared or not in the current scope.