Display Image in Image Control on DataList ImageButton Click using C# and VB.Net in ASP.Net

Last Reply 7 months ago By pandeyism

Posted 7 months ago

Dear sir,

I have a datalist control. When user click datalist imagebutton i need it big image to image control in same page. i used below code but i get a error. 

HTML

<asp:DataList ID="DataList1" runat="server" HorizontalAlign="Left" OnItemCommand="DataList1_ItemCommand"
    RepeatColumns="6" RepeatDirection="Horizontal" Width="319px">
    <ItemTemplate>
        <table class="style1">
            <tr>
                <td>
                    <asp:ImageButton ID="ImageButton1" runat="server" CommandName="itemclick" Height="50px"
                        ImageUrl='<%# Eval("image") %>' Width="50px" />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("id") %>' />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

 

 

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "itemclick")
    {
        itemid = int.Parse(((HiddenField)e.Item.FindControl("HiddenField2")).Value);
        DataTable dt = db.Table("select * from tbproduct where id='" + itemid + "'");
        Image2.ImageUrl = dt.Rows[0]["image"].ToString();
    }
}

 

This question does not have replies that have been liked.