我认为同样的事情也适用于数据列表,但我一直在后面的代码中使用它作为中继器。Mayby 使用 DataListItemEventArgs 和 DataListCommandEventArgs 代替中继器。
protected void rptUserInfo_Data(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
UserInfo oUserInfo = e.Item.DataItem as UserInfo;
LinkButton hlUser = e.Item.FindControl("hlUser") as LinkButton;
hlUser.Text = oUserInfo.Name;
hlUser.CommandArgument = oUserInfo.UserID + ";" + oUserInfo.uName;
hlUser.CommandName = "User";
}
}
public void UserArtItem_Command(Object sende, RepeaterCommandEventArgs e)
{
if (e.CommandName == "User")
{
string command = e.CommandArgument.ToString();
string[] split = command.Split(new Char[] { ';' });
Session["ArtUserId"] = split[0];
Session["ArtUserName"] = split[1];
Response.Redirect("~/Author/" + split[1]);
}
}