Solved

how can I get a value from a control in datalist

Posted on 2011-02-25
2
267 Views
Last Modified: 2012-06-27
Hi experts

I have an image button in a datalist shows products repeatly,its databinded to a datatable .
I wish to get the product id and show the detail of the product in a modalpopup panel.
but I dont know how to get that id from databinding .

thanks


0
Comment
Question by:hukaka
2 Comments
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 500 total points
Comment Utility
Try the Code:

Aspx Page:

   <!-- Begin Category Listing -->
                                    <asp:datalist id="dlCategories" runat="server">
                                        <ItemTemplate>
                                            <P class="wht_14" style="MARGIN: 8px 18px 2px 0px" align="right"><b>
                                                   
                                                    <asp:LinkButton id="Linkbutton1" Runat="server" CommandArgument='<%# Container.DataItem("categoryID") %>' CommandName="Edit">
                                                        <%#Container.DataItem("CategoryName")%>
                                                    </asp:LinkButton></b>
                                                    </P>
                                            <!-- Begin Product Listing -->
                                            <asp:Panel id="PanelProd" runat="server" Visible="false">
                                                <asp:DataList ID="dlProd" Runat="server">
                                                    <ItemTemplate>
                                                        <P class="wht_11" style="MARGIN: 0px 26px 4px 0px" align="right">
                                                        <asp:Image ID="imgArrow" Runat="server" Visible="False" ImageUrl="/images/ico_arrowRight.gif"></asp:Image>
                                                        <asp:LinkButton id="linkButton2" Runat="server" OnClick="ProductDetailClicked" CommandArgument='<%# Container.DataItem("productsID") %>'>
                                                                <%#Container.DataItem("ProductName")%>
                                                            </asp:LinkButton></P>
                                                    </ItemTemplate>
                                                </asp:DataList>
                                               
                                            </asp:Panel>
                                            <!-- End Product Listing -->
                                        </ItemTemplate>
                                    </asp:datalist>
                                    <!-- End Category Listing -->

Code Page:

Public Sub ProductDetailClicked(ByVal sender As Object, ByVal e As EventArgs)

        PanelMainProducts.Visible = False
        PanelProduct.Visible = True
        myConnection = New SqlConnection(conString)
        myConnection.Open()

        mycommand = New SqlCommand("getSpecificProduct", myConnection)
        mycommand.CommandType = CommandType.StoredProcedure

        Dim objButton As LinkButton

        If Session("ProdID") = "" Then
            objButton = CType(sender, LinkButton)
            mycommand.Parameters.Add(New SqlParameter("@productsID", SqlDbType.Int))
            mycommand.Parameters("@productsID").Value = objButton.CommandArgument
        Else
            mycommand.Parameters.Add(New SqlParameter("@productsID", SqlDbType.Int))
            mycommand.Parameters("@productsID").Value = sender
        End If

        myReader = mycommand.ExecuteReader

        Me.Bind_Data(myReader)

        myConnection.Close()

        Dim imgArrow As System.web.UI.WebControls.Image
        Dim i As Integer

        Do While i < Me.dlCategories.Items.Count

            imgArrow = CType(Me.dlProd.Items(i).FindControl("imgArrow"), System.Web.UI.WebControls.Image)
            imgArrow.Visible = True
            i = i + 1
        Loop

    End Sub
0
 

Author Comment

by:hukaka
Comment Utility
wow
thank you agarwalrahul
for writing so many code in midnight
will check it tomorrow

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
javascript call 6 34
comparing string in C# 3 31
Jquery autocomplete 10 17
bulid json format 3 15
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now