当用户单击linkButton OnItemCommand时,不会触发。从不调用ItemCommand事件。该代码运行并生成div并显示正确的数据,因此我知道此人对象已正确绑定,但是单击链接按钮不起作用,因为从不触发MatchList_ItemCommand。
我一直在搜索几天,但是遇到的任何事情都无法为我解决此问题。我没发现这段代码有什么问题。
(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("Name LIKE '%{0}%' OR ID LIKE '%{0}%'", searchTextBox.Text);
<asp:Panel ID="matchListPnl" runat="server" Visible="false">
<h1>Look Up Person: Results</h1>
<p><asp:Label ID="matchListLbl" runat="server"></asp:Label> Clicking the name loads it for administration.</p>
<asp:Panel ID="exactMatchPnl" runat="server" Visible="false">
<h2><asp:Label ID="exactMatchLbl" runat="server"></asp:Label></h2>
<asp:Repeater ID="exactMatchList" runat="server" OnItemCommand="MatchList_ItemCommand"/>
</asp:Panel>
<br />
<asp:Panel ID="partialMatchPnl" runat="server" Visible="false">
<h2><asp:Label ID="partialMatchLbl" runat="server"></asp:Label></h2>
<asp:Repeater ID="partialMatchList" runat="server" OnItemCommand="MatchList_ItemCommand"/>
</asp:Panel>
</asp:Panel>
protected void MatchList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
PersonLinkButton btn = (PersonLinkButton)e.CommandSource;
Person person = btn.Person;
//person.Refresh();
Session["AdminPersonToEdit"] = person;
LogAdminAction("Show account details on " + person.LastName + ", " + person.FirstName + " (" + person.Uid + ")");
Response.Redirect("DetailView.aspx", true);
}
public class LastNameSearchTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
//add the beginning div tag
container.Controls.Add(new LiteralControl("<div class=\"resultsBox\">"));
//create the link to the person
PersonLinkButton personLinkBtn = new PersonLinkButton();
personLinkBtn.DataBinding += new EventHandler(PersonLinkBtn_DataBinding);
container.Controls.Add(personLinkBtn);
//add any extra data about the user
Label personInfoLbl = new Label();
personInfoLbl.DataBinding += new EventHandler(PersonInfoLbl_DataBinding);
container.Controls.Add(personInfoLbl);
//add the end div
container.Controls.Add(new LiteralControl("</div>"));
}
/// <summary>
/// Bind person data to a PersonLinkButton. This is the link in the repeater that allows the admin to select a person.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PersonLinkBtn_DataBinding(object sender, EventArgs e)
{
PersonLinkButton btn = (PersonLinkButton)sender;
btn.Font.Bold = true;
RepeaterItem container = (RepeaterItem)btn.NamingContainer;
Person person = (Person)container.DataItem;
btn.Person = person;
//set the text for the link first
if (btn.Person.LastName != string.Empty)
{
if (btn.Person.LastName != btn.Person.FirstName + ",")
{
btn.Text = btn.Person.LastName;
if (btn.Person.FirstName != string.Empty)
{
btn.Text += ", " + btn.Person.FirstName;
}
}
else
{
btn.Text += ", " + btn.Person.DisplayName;
}
}
else if (btn.Person.FirstName != string.Empty)
{
btn.Text = btn.Person.FirstName;
}
else if (btn.Person.Uid != string.Empty)
{
btn.Text = btn.Person.Uid;
}
}
/// <summary>
/// Binds person data to a label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PersonInfoLbl_DataBinding(object sender, EventArgs e)
{
Label lbl = (Label)sender;
RepeaterItem container = (RepeaterItem)lbl.NamingContainer;
Person person = (Person)container.DataItem;
//get first name and uid first
//next show any student data
bool showData = false;
string displayName = string.Empty;
string uid = string.Empty;
string dob = string.Empty;
string ssn4 = string.Empty;
if (person.IsFound)
{
displayName = person.DisplayName;
uid = person.Uid;
dob = person.Dob;
ssn4 = person.Ssn4;
showData = true;
}
if (showData)
{
lbl.Text += "<br/>Name: <em>" + displayName + "</em>";
lbl.Text += "<br/>Uid: <em>" + uid + "</em>";
lbl.Text += "<br/>DOB: <em>" + dob + "</em>";
lbl.Text += "<br/>SSN4: <em>" + ssn4 + "</em>";
}
}
}