-1

我创建了一个列表视图。每当我选择一个项目时,我想将该值传递给另一个事件以编辑和删除所选记录。

我怎样才能做到这一点?

这是代码:

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(); 
}
4

2 回答 2

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
}
于 2012-09-05T08:15:10.253 回答
0

这里有很多场景
第一个:-通过java脚本在客户端进行选择更改附加onclick按钮编辑和删除功能,并使用onselection更改事件选择的值

第二:- 在会话中设置值并进一步使用它

于 2012-09-05T07:05:01.483 回答