Solved

how can I get a value from a control in datalist

Posted on 2011-02-25
2
270 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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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