Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a datalist with 1 button, but depending on how many records are returned i would like to use Response.Redirect to determine which query string will paear on the following page. Here is an example. On the button clcik event I have.

C#
protected void InstallChecklist_TW_Click(object sender, EventArgs e)
    {
        string Install1Name_TW = ((Label)DataList1.Items[0].FindControl("InstallName_TW")).Text;
               
          Response.Redirect("tespage.aspx?InstallName_TW=" + Install1Name_TW);

     }


This works as expected and passes the querystring. So I guess this would be for my datalist button index 0 and my datalist label index 0. However, at times there will be more than one record and I will need to pass the querystring for button index 1 and label index 1 and so on. How can this be done.

Is there a way That I can say if button index 1 is pressed do this and so on..?

Thanks In Advance.
Posted
Updated 18-Mar-13 9:46am
v2
Comments
frostcox 18-Mar-13 15:50pm    
Just loop through the datalist items and append the data on to the query string??
Dustin Prevatt 18-Mar-13 16:41pm    
could you give me an example? Sorry i'm still pretty new at this :)

C#
protected void InstallChecklist_TW_Click(object sender, EventArgs e)
    {
       string sUrl = String.Empty;
       foreach(DataListItem item in DataList1.Items)
       {
            if(item is Label)
            {
             Label lbl = (Label)item;
             sUrl += "&" + lbl.Text + "=" lbl.Text;
            }
       }
       sUrl = sUrl.TrimStart('&');
       Response.Redirect("tespage.aspx?" + sUrl);
     }
 
Share this answer
 
Comments
Dustin Prevatt 18-Mar-13 17:53pm    
i tried your code but it looks like it is looking for a ";" between lbl.text
frostcox 18-Mar-13 18:00pm    
Can you post what error you are getting? I wrote this free hand so I might have missed something.
I ended up using the following code:

C#
DataListItem item = (sender as Button).NamingContainer as DataListItem;
string str1 = (item.FindControl("InstallName_TW") as Label).Text;
Response.Redirect("tespage.aspx?InstallName_TW=" + str1);


Thanks everyone for the help!
 
Share this answer
 

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