我在VB.net中编程。我试图通过搜索我的数据库的电子邮件地址来填充2个gridview表。当用户点击搜索按钮时,我希望我的程序从文本框中获取值,在我的数据库中搜索电子邮件地址,然后在我的'ScrumMaster'表和我的'Developers'表中显示用户配置文件。我不知道如何在一个'btnSearchEmail_Click'方法中实现所有这一切。目前我的代码是
Protected Sub btnSearchEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchEmail.Click
End Sub
Protected Sub ScrumMastersDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles ScrumMastersDataSource.Selecting
Dim db As New AgileClassesDataContext()
Dim enteredEmail = txtEnteredEmail.Text
Dim scrumMasters = (From u In db.Users
Join ur In db.UserRoles On u.UserId Equals ur.UserId
Join r In db.Roles On ur.RoleId Equals r.RoleId
Where r.RoleId = 2 And u.Email = enteredEmail
Select u).Distinct
e.Result = scrumMasters
End Sub
Protected Sub DevelopersDataSource_Selecting(sender As Object, e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles DevelopersDataSource.Selecting
Dim db As New AgileClassesDataContext()
Dim enteredEmail = txtEnteredEmail.Text
Dim developers = (From u In db.Users
Join ur In db.UserRoles On u.UserId Equals ur.UserId
Join r In db.Roles On ur.RoleId Equals r.RoleId
Where r.RoleId = 3 And u.Email = enteredEmail
Select u).Distinct
e.Result = developers
End Sub
正如您所看到的,这里有3种方法。我想在'btnSearchEmail_Click'事件中放置'ScrumMastersDataSource_Selecting'和'DevelopersDataSource_Selecting',以便它们在单击'btnSearchEmail'时运行。由于电子邮件地址可能与开发人员和Scrum主控角色相关联,因此复制不是问题。任何的建议都受欢迎。我希望这个问题有道理
答案 0 :(得分:0)
尝试这样的事情(这是C#/ VB.NET的混合):
private void RefreshGrids()
{
ScrumMastersDataSource.DataSource = GetListScrum(txtEnteredEmail.Text);
ScrumMastersDataSource.DataBind();
DevelopersDataSource.DataSource = GetListDev(txtEnteredEmail.Text);
DevelopersDataSource.DataBind();
}
Protected Sub btnSearchEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchEmail.Click
RefreshGrids();
End Sub