我想调用ListView的SelectedIndexChanged方法,但它不会在运行时进入SelectedIndexChanged方法。这是我的代码。
<asp:ListView ID="LeftsideMessageList" runat="server" ItemPlaceholderID="itemPlaceHolder1" DataKeyNames="id" OnSelectedIndexChanged="LeftsideMessageList_SelectedIndexChanged" >
代码背后:
protected void LeftsideMessageList_SelectedIndexChanged(object sender, EventArgs e)
{
string pid = LeftsideMessageList.SelectedDataKey.Value.ToString();
MessageBusinessClass MBC = new MessageBusinessClass();
string x = pid;
int id = Convert.ToInt32(x);
var grouplist = MBC.getSpecificGroup(x, Session["Username"].ToString()); //session
Session["Groupname"] = grouplist.GroupName;
Session["REmail"] = grouplist.Recipient.Email; // message to
GetRightMessageList(grouplist.Recipient.Email);
}
编辑:
我有一个LinkButton,我曾经用它来调用该方法,但是我删除了它,并希望使用item selected事件来调用该方法。
<asp:LinkButton ID="lnkSelect" runat="server" ForeColor="White" >
答案 0 :(得分:-1)
您需要将AutoPostBack属性设置为true
<asp:ListView ID="LeftsideMessageList" runat="server" AutoPostBack="true" ItemPlaceholderID="itemPlaceHolder1" DataKeyNames="id" OnSelectedIndexChanged="LeftsideMessageList_SelectedIndexChanged" >
答案 1 :(得分:-2)
设置AutoPostBack="true"
<asp:ListView ID="LeftsideMessageList" runat="server" ItemPlaceholderID="itemPlaceHolder1" DataKeyNames="id" OnSelectedIndexChanged="LeftsideMessageList_SelectedIndexChanged" AutoPostBack="true">