Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can I get a value from a control in datalist

Posted on 2011-02-25
2
Medium Priority
?
275 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:
Rahul Agarwal earned 2000 total points
ID: 34986057
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
ID: 34986325
wow
thank you agarwalrahul
for writing so many code in midnight
will check it tomorrow

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

971 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