Click here to Skip to main content
15,885,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using an asp.net ImageButton for post back url. In user.aspx page there are images of other users within a datalist.

I want when I click any of those pictures the selected user s details should display on the user page. What do I have to do for that.

In my ImageButton I use post back url like this
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# GetImageURL(Eval("Pic")) %>' PostBackUrl='<%# Eval("id", "user.aspx?id={0}") %>'/>

and in page load code
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Session("UName") Is Nothing Then
        Response.Redirect("login.aspx")
    Else
        If Not (IsPostBack) Then
            binddata()
            binddata1()
            binddata2()
        End If
    End If
End Sub

and use query string on databind like this
VB
Sub binddata()
    Dim mycommand As New SqlCommand("SELECT * FROM details where id = @id", con)
    mycommand.Parameters.Add("@id", SqlDbType.Int)
    mycommand.Parameters("@id").Value = Convert.ToInt32(Request.QueryString("id"))
    con.Open()
    userData.DataSource = mycommand.ExecuteReader
    userData.DataBind()
    con.Close()
End Sub

but it is not working. I am not able to catch where I am going wrong. Please help me with this.

[edit] - formatted code blocks and some minor grammer changes
Posted
Updated 22-Nov-11 22:33pm
v2
Comments
Pandya Anil 23-Nov-11 4:45am    
what is the error you facing ? not working doesnot explain anything, check 'View Source' of page to findout what is the final URL bound to datalist's items, debug it step by step to reach to the actual problem
Reiss 23-Nov-11 5:06am    
I would suggest it is because you are not calling your binddata() sub on the post back event

1 solution

Try

replacing
C#
PostBackUrl='<%# Eval("id", "user.aspx?id={0}") %>'

with
C#
PostBackUrl='<%# Eval(Container.DataItem, "id", "user.aspx?id={0}") %>'


Thanks,
hemant
 
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