Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi....all
I have created one user control that contain datalist.datalist contain one image and three label field.this all controls i want to bind at runtime from aspx page...
how can i bind this datalist from aspx page.i have written following code for ascx page...
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" 
    style="top: 66px; left: 48px; position: absolute">
    <footertemplate>
                   
    </footertemplate>
    <HeaderTemplate>
        <div class="style1">
            <h2>
                Products</h2>
        </div>
    </HeaderTemplate>
    <itemtemplate>
        <asp:Image ID="Image1" runat="server" Height="227px" Width="232px" />
        <br />
        <asp:Label ID="Label3" runat="server" Text='<%# Eval("Product_Name") %>'>
        
        <br />
        Market Price:<asp:Label ID="Label1" runat="server" 
            Text='<%# Eval("Market_Prize") %>' Font-Strikeout="True">
        <br />
        Offer Price :   <asp:Label ID="Label2" 
            runat="server" Text='<%# Eval("Offer_Prize") %>'>
        
        <br />
        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/btndetails_gtex.gif" />
        <br />
    </itemtemplate>

how to bind these field....
please help me
Posted
Updated 10-Jun-11 2:34am
v2

This is how you create a user control : MSDN
And for data binding you can expose a property (say "datasource") from your user control. Use this property's set accessor to set bind the listview. Try this link as well.
 
Share this answer
 
Comments
keyur_patel35 10-Jun-11 12:11pm    
Thankx...for reply....and i got the solution....thanks again
Hi,

Create a public function in UserControl that will do the databinding. From aspx page that contains the UserControl invoke the function to bind. In this case if you want you can also supply datasource (i.e. DataTable/Collection) as a parameter to bind DataList in UserControl. Hope this will solve your problem.
 
Share this answer
 
Comments
keyur_patel35 10-Jun-11 12:12pm    
Thanks i does exactly you suggest...and it works...thanks

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