Saturday, March 10, 2012

datalist control in asp.net

In previous articles i explained how to bind data to dropdownlist and Gridview,Export Gridview data to PDF document,dynamically add rows to Grid view in asp.net using c#. Here i will show how to display the images with zooming option in Data list.Data list doesn't provide built in structure for presenting data.So we(developers) provide required custom structure.The Grid view is not applicable for this above requirement .because grid view comes with Table structure,This can not be changed.We can use Repeater for this Requirement
Default.aspx:
<Header Template>
</HeaderTemplate><Header Style Horizontal Align="center" BackCoor="aqua" ForeColor="Blue"/>
<ItemTemplate>
<asp:Lable id="l1" runat="server" Text='<% #Eval("name")%>'>
</asp:Lable><br/>
<asp:Image src='<% #Eval("name")%>' Height="60" Width="60">
<br/>
<asp:Panel id="p1" runat="server" Height="60" Width="60" scrollBars="vertical">
<% #Eval("name")%>
</asp:Panel><br/>
<asp:CheckBox id="c1" runat="server" />
<br/>
<asp:Button  id="btn" runat="server" Text="Zoom" CommandArgument='<% #Eval("name")%>'/>
</ItemTemplate>
<ItemStyle BackColor="Blue" Bordrcolor="Yellow" Borderstyle="Dotted"/>
<FooterTemplate>
No of wonders=<% #Datalist1.Items.count%>
</FooterTemplate>


Codebehind:
if(Page.isPostBack==false)
{
Dabaselib.mycomponent obj=New databaselib.mycomponent();
Dataset ds=onj.Getinfo("useid="sa"; password=; Database="test","Select*from wonders");
Datalist1.Datasource=ds.Tables[0];
Datalist1.DataBind();
}
When use click zoom button postback will takes place.ItemCommand event of datalist will be excuted.Item Command event will proivde Command Argument value of selected button
//Zoom when we clik on image
protected void Datalist1-itemCommand(Object sender, DataListCommandEventArgs e) 
{
Response.Write("zoom.aspx?="+e.CommandArgument);
}
The zoom.aspx will show the image with zooming

No comments:

Bel