新しい管理者のために。私のアプリケーションの機能には、GridView
データベースにレコードを表示する機能があります。
TextBox
ユーザーがスタッフ名を入力して「検索」ボタンをクリックするための があります。ListBox
検索結果を(似たようなスタッフ名を表示)で表示したい。ユーザーが名前をクリックすると、自動的にデータベースに挿入され、GridView
.
ListBox
に基づいてデータバインドするにはどうすればよいTextBox
ですか? また、ユーザーがクリックしたときに値を挿入するにはどうすればよいListBox
ですか? ありがとう。
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ITAlert.aspx.vb" Inherits="DepartmentManager_ITAlert" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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>
コード ビハインド (提案されたリストボックス データバインド関数を使用):
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
また、検索機能のLINQでエラーを表示する
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