Hi,
I have created a listview that represents data in a tabular format. The last column of the listview has a link button. I want to be able to click on the link to redirect the page to a new page by passing the cell values of that row in the query string. I dont know how to get the cell values of a given row in the listview. I am working with ASP.NET and C#. Can anyone kindly help me with this please? Thanks.
Mohan
Loading
Amit ChoudharyPosted Feb 19, 2010, 10:39 AM
void ContactsListView_SelectedIndexChanged(Object sender, EventArgs e)
{
if (ContactsListView.SelectedIndex >= 0)
ViewState["SelectedKey"] = ContactsListView.SelectedValue;
else
ViewState["SelectedKey"] = null;
}
no in your button click event try this
protected void editListView(object sender, EventArgs e){
System.Web.UI.WebControls.Label firstcell = (System.Web.UI.WebControls.Label)selectedtickets1.Items[(int)ViewState["SelectedKey"] ].FindControl("id");
}
i hope it solve your problem.
Mohan MudaliarPosted Feb 25, 2010, 8:55 AM
Thank you for your response and sorry for the late reply. Your solution worked and was able to fix the problem. During the course of troubleshooting, I found another way of doing the same. I over rided the edit method of the list view to direct me to a different page. Thank you once again. You help is much appreciated.
Regards,
Mohan
Mohan MudaliarPosted Feb 18, 2010, 10:04 AM
Thank you once again. I tried the code that you sent. However, I am getting the following error message:
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
My function looks like this:
protected void editListView(object sender, EventArgs e){
System.Web.UI.WebControls.Label firstcell = (System.Web.UI.WebControls.Label)selectedtickets1.Items[selectedtickets1.SelectedIndex].FindControl("id");
System.Web.UI.WebControls.Label secondcell= (System.Web.UI.WebControls.Label)selectedtickets1.Items[selectedtickets1.SelectedIndex].FindControl("status_type");
Response.Redirect("~/rims/details.aspx?id=" + firstcell .Text + "&stsid=" + secondcell.Text);
}
Regards,
Mohan
Amit ChoudharyPosted Feb 18, 2010, 8:08 AM
try this inside the button click event:
Label firstcell=(Label)ListView1.Items[ListView1.SelectedIndex].FindControl("lblModuleTitle");
string firstParameter=firstcell.Text;
Mohan MudaliarPosted Feb 18, 2010, 7:02 AM
Thank you for replying.
Just to clarify myself further, what I have is a table (in a listview) with say 6 columns and 10 rows. I have 10 buttons on the 6th column to represent each row. What I need to do is to be able to click on the button of any given row that will pass the first and the second cell values of that row as parameters in the query string and redirect the page to a different page with these query string parameters.
I would be grateful to you if you could explain this a little more. An example would be much appreciated.
Thanks, Mohan
Amit ChoudharyPosted Feb 18, 2010, 5:37 AM
which value you want to fetch from the list view?? if it is your Unique id then you can associate it with your linkbutton's CommandArgument property using Eval() or other bind function.
if there is other case than this then please mention it here? so that i can give you exact help you want.