![](/img/trans.png)
[英]how can i split email id and display the text before @ in another textbox in asp.net c#
[英]How do I get a ListBox to display all info for an "ID" from a Textbox (ASP.NET C#)
我正在處理一個項目,我想在其中顯示客戶的所有事件信息(來自數據庫)(我從文本框/用戶輸入中獲得)。
我正在努力填充 ListBox 並且不確定到目前為止我對使用“RowFilter”函數是否有正確的想法。
public partial class CustomerSurvey : System.Web.UI.Page
{
private Incident incidentInformation;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnGet_Incidents(object sender, EventArgs e)
{
incidentInformation = this.GetInfoForSelectedCustomerID();
}
private Incident GetInfoForSelectedCustomerID()
{
//get row from AccessDataSource based on value in dropdownlist
DataView customersTable = (DataView)
SqlDataSource2.Select(DataSourceSelectArguments.Empty);
customersTable.RowFilter =
"CustomerID = '" + txtCustomerID_ForIncidents + "'";
DataRowView row = (DataRowView)customersTable[0];
//create a new product object and load with data from row
Incident i = new Incident();
i.IncidentID = (int)row["IncidentID"];
i.CustomerID = (int)row["CustomerID"];
i.ProductCode = row["ProductCode"].ToString();
i.TechID = (int)row["TechID"];
i.DateOpened = (DateTime)row["DateOpened"];
i.DateClosed = (DateTime)row["DateClosed"];
i.Title = row["Title"].ToString();
i.Description = row["Description"].ToString();
return i;
}
private void DisplayInfo()
{
Incident incident = (Incident)Session["Reservation"];
lstCustomers.Display
}
如您所見,函數 DisplayInfo 未完成。 這是因為我不知道如何填充 ListBox。
我正在考慮的另一件事是,客戶可能會發生多起事件,我不確定我對課程的處理方法是否正確。
謝謝!
是否要根據 ListBox 中的 Textbox 值顯示數據庫中的數據? 如果是這樣,您可以參考下面的代碼。 如果我誤解了您的要求,請發布有關您的要求的更多詳細信息。
Aspx,
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> CustomerId:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="btnGet_Incidents" /> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ThreadDemoConnectionString %>" SelectCommand="SELECT [CustomerId], [Name], [Country] FROM [Customers]"></asp:SqlDataSource>
Aspx.cs:
protected void btnGet_Incidents(object sender, EventArgs e)
{
ListBox1.Items.Clear();
GetInfoForSelectedCustomerID();
}
private void GetInfoForSelectedCustomerID()
{
//get row from AccessDataSource based on value in dropdownlist
DataView customersTable = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
customersTable.RowFilter = "CustomerId = '" + TextBox1.Text + "'";
DataRowView row = (DataRowView)customersTable[0];
ListBox1.Items.Add(row["CustomerId"].ToString());
ListBox1.Items.Add(row["Name"].ToString());
ListBox1.Items.Add(row["Country"].ToString());
}
結果,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.