Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Here is my View.aspx 


ASP.NET
<form id="Form1" runat="server">
    <div id="container" style="float:left; background-color:White">
        <div id="levels">       
            <div style="float:left;">
            <asp:DataList ID="outerDataList" runat="server" RepeatDirection="Vertical" 
                    Width="100%" onitemdatabound="outerDataList_ItemDataBound" DataKeyField="EId" EnableViewState="False" GridLines="None">
                <ItemTemplate>
                <table>
                    <tr>
                        <td rowspan="20" align="center">                                                        
                            <asp:ImageButton runat="server" ID="ImgEp" OnClick="imgbtn_Click" AlternateText='<%#DataBinder.Eval(Container.DataItem, "EImage")%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem, "EId")%>' ImageUrl='<%# Eval("EImage") %>'/>
                            <%--<a href='ViewLevels.aspx?Id=<%# Eval("EId")%>'><img id="ImgEp" src='<%# Eval("EImage") %>' width="250" height="250" alt="Candy Crush Saga Help Episode <%# Eval("EId") %> - <%# Eval("Ename") %>" title="Candy Crush Saga Help Episode <%# Eval("EId") %> - <%# Eval("Ename") %> "></a>--%>
                        </td>
                        <td>                        
                            <asp:HiddenField runat="server" ID="hdnId" Value='<%# Eval("EId") %>' />
                            <asp:Label Font-Bold="true" ID="lblCategoryName" runat="server" Text='<%# Eval("Ename") %>'/><br />
                        <ul>
                            <asp:DataList ID="innerDataList" runat="server" DataKeyField="LEpisodeId">
                                <ItemTemplate>                                    
                                        <li>
                                            <a href="ViewLevels.aspx">                           
                                            <asp:LinkButton ID="lnkbtn" runat="server"> Level <%# Eval("LId")%> Help, Tips and Hints</asp:LinkButton></a><br />
                                        </li>                                    
                                </ItemTemplate>
                            </asp:DataList>                            
                        </ul>
                        </td>
                    </tr>                    
                </table>
                </ItemTemplate>
                <AlternatingItemStyle BackColor="White" ForeColor="Black" />
                <ItemStyle VerticalAlign="Top" BackColor="White" ForeColor="Black"/>
            </asp:DataList>
            </div>    
        </div>
    </div>        
</form>

<pre lang="text">
here is view .aspx.cs code

C#
BLayer objBal = new BLayer();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindEpisodesDl();            
        }
    }

    private void BindEpisodesDl()
    {
        Hashtable ht = new Hashtable();
        DataSet ds = new DataSet();

        objBal.ExcuteQuery(Constant.BindAllEpisodes_sp, ht, ds);
        ViewState["vs"] = ds.Tables[1];

        outerDataList.DataSource = ds.Tables[0];
        outerDataList.DataBind();
    }

    protected void outerDataList_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Hashtable ht = new Hashtable();
            DataTable dt1 = (DataTable)ViewState["vs"];

            DataList dlin = (DataList)e.Item.FindControl("innerDataList");
            HiddenField hid = (HiddenField)e.Item.FindControl("hdnId");

            DataTable Cdt = new DataTable();
            Cdt = dt1.Clone();

            DataRow[] Cdrr = dt1.Select("EId =" + hid.Value);
            foreach (DataRow dr2 in Cdrr)
            {
                Cdt.ImportRow(dr2);
            }
            dlin.DataSource = Cdt;
            dlin.DataBind();
        }
    }

    protected void imgbtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("ViewLevels.aspx");
    }



please help me how to fire click events on image button asp:ImageButton ID="ImgEp" and linkbutton asp:LinkButton ID="lnkbtn"
Posted

Give command name field for image button like this:

XML
<ItemTemplate>
<asp:ImageButton ID="Image1" runat="server" CommandArgument='<%# Eval("product_id") %>' CommandName="click" Height="200px" ImageUrl='<%# Eval("url")%>' Width="200px" />
        </ItemTemplate>



and then in code behind:

protected void Datalist1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "click")
        {
            // your logic
        }
     }
 
Share this answer
 
v3
Comments
rameshk14 5-Feb-14 2:22am    
thank u for your reply.
if i try in that a way also not working this itemcommand event
Jignesh Khant 5-Feb-14 2:30am    
I have tried this code in one of my projects, it works fine. See carefully you might be missing something.
Hemant__Sharma 5-Feb-14 3:27am    
+4 proposing accurate property/attribute name which is missing.
rameshk14 5-Feb-14 5:15am    
now its working in ie browser.... but not working in other ie
Jignesh Khant 5-Feb-14 5:40am    
Browser has got nothing to do with code.
 
Share this answer
 
There are 2 problems I see with your code - 1st missing CommandName property in aspx code and you can follow solution proposed by @Jignesh Khant.

2nd you are missing event handler in your aspx code for datalist control. For that you should specify event binding for Itemcommand i.e.
onitemcommand="outerDataList_ItemCommand"
the way you have done it for
onitemdatabound
event.

Without event handling Asp.net Runtime would never know that outerDataList_ItemCommand function is handled by outerDataList's itemCommand event.
 
Share this answer
 
v2

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