如何使用Ajax ModalPopUpExtender控件在ListView中获取所选行的ID? [英] How to get the ID of the selected row in the ListView with Ajax ModalPopUpExtender control?
问题描述
我有一个ListView,其中显示了员工提交的建议.在此ListView的最后一列中,我有一个(状态)列,该列将由管理员更新.当管理员单击它时,将打开带有RadioButtonList的ModalPopUpExtender,其中显示(Status)的可能选项.无论如何,我现在需要获取管理员单击该建议的状态"单元格的行的ID.我需要在以后使用它向该建议的所有者发送电子邮件通知.
除了GridView控件,我已经做了所有这些事情,如下所示:
I have a ListView that shows the suggestions submitted by the employees. In the last column of this ListView, I have a (Status) column that will be updated by the Admin. When the Admin clicks on it, a ModalPopUpExtender will be opened with RadioButtonList that shows the possible options for (Status). Anyway, I need now to get the ID of the row where the Admin clicked on the Status cell of that suggestion. I need in order to use it later on for sending an email notification to the owner of that suggestion.
I already did of all this but for GridView control as following:
protected void lnkSuggestionStatus_Click(object sender, EventArgs e)
{
LinkButton lnkSuggestionStatus = sender as LinkButton;
//var safetySuggestionsId =
//get reference to the row selected
GridViewRow gvrow = (GridViewRow)lnkSuggestionStatus.NamingContainer;
//set the selected index to the selected row so that the selected row will be highlighted
GridView1.SelectedIndex = gvrow.RowIndex;
//This HiddenField used to store the value of the ID
HiddenField1.Value = GridView1.DataKeys[gvrow.RowIndex].Value.ToString();
//ViewState["Username"] = gvrow.Cells[4].Text;
//show the modalPopUp
modalPopUpExtender1.Show();
}
但是我现在需要它用于ListView, **所以该怎么做?**
当前隐藏代码:
But I need it now for the ListView, **so How to do that?**
Current Code-Behind:
protected void lnkSuggestionStatus_Click1(object sender, EventArgs e)
{
LinkButton lnkSuggestionStatus1 = sender as LinkButton;
//show the modalPopUp
modalPopUpExtender2.Show();
}
推荐答案
您需要设置ListView的DataKeyNames
,然后
You need to setDataKeyNames
of your ListView and then
protected void lnkSuggestionStatus_Click1(object sender, EventArgs e)
{
ListViewDataItem item = (ListViewDataItem)(sender as Control).NamingContainer;
string idValue= ListView1.DataKeys[item.DataItemIndex].Value.ToString();
}
这篇关于如何使用Ajax ModalPopUpExtender控件在ListView中获取所选行的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!