Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Everyone,

I want to access the database value in the linkbutton and then on_click want to send it on to next page. But I can't get it done. Please HELP!!

This is my source code:-

XML
<asp:DataList ID="DataList1" runat="server" DataKeyNames="Img" xmlns:asp="#unknown" RepeatDirection="Horizontal" RepeatColumns="3" >

                         <ItemTemplate>
                         <ul>
                           <li>
                              <img src='cap/<%#Eval("Img") %>' height="150px" width="210px"></img>
                              <label id="label1"><asp:LinkButton id="lnk1" runat="server"
                                   id='cap/<%#Eval("Img") %>' onclick="lnk1_Click" >View Details</asp:LinkButton></label>
                           </li>

                         </ul>
                         </ItemTemplate>

                       </asp:DataList>



And this is my on_click event:-

C#
protected void lnk1_Click(object sender, EventArgs e)
    {
        LinkButton lnk1 = sender as LinkButton;
        Label2.Text = lnk1.Text;
        Response.Redirect("album.aspx?pid=" + Label2.Text);

    }


The problem is although the image is available via same code, I can't access value in the linkbutton 'View Details'.

Urgent Help Needed!!
Posted
Comments
ZurdoDev 4-Jun-15 9:31am    
You have to use DataList1.FindControl()
Deepak Kanswal Sharma 4-Jun-15 11:26am    
Thanks Ryan, But where and how can I use it?
ZurdoDev 4-Jun-15 12:03pm    
Google for FindControl examples. There's lots.
Deepak Kanswal Sharma 5-Jun-15 12:13pm    
Ok I tried this thing, but it didn't work:-

protected void lnk1_Click(object sender, EventArgs e)
{
LinkButton lnk1 = sender as LinkButton;
Label2.Text= ((Label)DataList1.SelectedItem.FindControl("lnk1")).Text;
Response.Redirect("album.aspx?pid=" + Label2.Text);

}

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