我创建了一个列表视图。每当我选择一个项目时,我想将该值传递给另一个事件,以便对所选记录进行编辑和删除。
我该怎么做?
以下是代码:
protected void userList_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
userList.SelectedIndex = e.NewSelectedIndex;
uid = userList.DataKeys[e.NewSelectedIndex].Value.ToString();
Label1.Text = "Selected username: " + uid;
BindGenerics();
}
答案 0 :(得分:0)
这里有很多场景 第1步: - 通过java脚本对客户端选择更改进行附加按钮onclick功能按钮编辑和删除选择更改事件选择的值
第二: - 在会话中设置值并进一步使用
答案 1 :(得分:0)
试试这个:
protected void userList_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
userList.SelectedIndex = e.NewSelectedIndex;
string uid = userList.DataKeys[e.NewSelectedIndex].Value.ToString();
Label1.Text = "Selected username: " + uid;
BindGenerics();
Session["SelectedUserId"] = uid;
}
protectec void edit_Click(Object sender, EventArgs e)
{
string uid = Session["SelectedUserId"].ToString();
// Do whatever with uid
}
protectec void delete_Click(Object sender, EventArgs e)
{
string uid = Session["SelectedUserId"].ToString();
// Do whatever with uid
}