Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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();
    }


But I need it now for the ListView, **so How to do that?**

Current Code-Behind:

C#
protected void lnkSuggestionStatus_Click1(object sender, EventArgs e)
    {
        LinkButton lnkSuggestionStatus1 = sender as LinkButton;

        //show the modalPopUp
        modalPopUpExtender2.Show();
    }
Posted

1 solution

You need to set DataKeyNames of your ListView and then

C#
protected void lnkSuggestionStatus_Click1(object sender, EventArgs e)
    {
        ListViewDataItem item = (ListViewDataItem)(sender as Control).NamingContainer;
        string idValue= ListView1.DataKeys[item.DataItemIndex].Value.ToString();

    }
 
Share this answer
 
Comments
matrix388 9-Jul-12 0:32am    
so no need for the HiddenField?
DamithSL 9-Jul-12 0:51am    
Answer cover only how you can get id from listview, you can use hidden field if you want to access it from somewhere else

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900