Solved

how can I get a value from a control in datalist

Posted on 2011-02-25
2
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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