Feeds:
Posts
Comments

Archive for the ‘C#.net’ Category

paging in asp:DataList

asp:DataList has to paging option by default but it is easy to make pagination in datalist using “PagedDataSource Class”

HTML code is:

<table width=”100%”>
<tr><td>
<asp:DataList ID=”dlPhotos” Runat=”server” Width=”100%” ItemStyle-HorizontalAlign=”Left” RepeatLayout=”Table” RepeatDirection=”Horizontal” RepeatColumns=”4″ OnItemDataBound=”dlPhotos_ItemDataBound”>
<ItemTemplate>
<asp:Image id=”imgThumbnail” runat=”server” borderSize=”5″ />
</ItemTemplate>
</asp:DataList>
</td></tr>
<tr><td>
<table width=”100%”>
<tr>
<td align=”left”><asp:LinkButton runat=”server” ID=”lnkPrev” OnClick=”lnkPrev_Click” >Prev</asp:LinkButton></td>
<td align=”right”><asp:LinkButton runat=”server” ID=”lnkNext” OnClick=”lnkNext_Click” >Next</asp:LinkButton></td>
</tr>
</table>
</td></tr>
</table>

Code for the pagination is:

public void ShowPhotos()
{
try
{
PagedDataSource objPage = new PagedDataSource();
DataSet dsImgs = ….\\datasource
objPage.AllowPaging=true;
objPage.DataSource = dsImgs.Tables[0].DefaultView;
objPage.PageSize = 12;
objPage.CurrentPageIndex = CurrentPage; //CurrentPage is a static variable
dlPhotos.DataSource = objPage;
dlPhotos.DataBind();
}
catch (Exception ex)
{
lblError.Text = ex.Message ;
}
}
protected void lnkPrev_Click(object sender, EventArgs e)
{
CurrentPage -=1;
ShowPhotos();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
CurrentPage+=1;
ShowPhotos();
}

thats just a sample, please customize it for your works

Advertisements

Read Full Post »

take a enum testEnum and a DropDownList ddlEnumData
public enum testEnum
{
one=1, two=2, three=3
}

foreach(testEnum te in Enum.GetValues(typeof(testEnum)))
{
  ddlEnumData.Items.Add(new ListItem(te.ToString(), Convert.ToInt32(te).ToString()));
}

Read Full Post »

This errors may appear when you are debugging , here are the how you will solve it

1. In the Internet Explorer, go to “Tools” -> “Internet Options”.

2. Switch to “Security” Tab.

3. Click on “Internet” (The Globe Icon. Its actually the default selected).

4. Click on “Custom Level” in the bottom.

5. Scroll down to find the “User Authentication” section.

6. Select “Automatic logon with current username and password”.

7. Click “Ok” twice to exit.

reference: http://geekswithblogs.net/ranganh/archive/2005/12/30/64446.aspx

Read Full Post »

take a placeholder on your page and the write this code on your event. 

ctlSudentAddress ctlAddress=(ctlSudentAddress)LoadControl(“ctlSudentAddress.ascx”);

ctlAddress.showStudentAddress(ID);

PlaceHolder1.Controls.Add(ctlAddress);

Read Full Post »

DataGrid in dot net 2.0

DataGrid contril is one of the most powerful control in asp.net Here is a vary good article of how to use DataGrid control in asp.net

http://www.devx.com/dotnet/Article/22141/0/page/1

Read Full Post »

Someitme we need to create control at runtime, Here is a good example to create control runtime.

http://www.developerfusion.co.uk/show/4393/

Read Full Post »

print a datagrid

<html>
    <head>
        <title>Data Grid print test</title>
        <script language=”javascript” type=”text/javascript”>
       
            function showReport()
            {
                var divGrid = document.getElementById( ‘divGrid’ );
                if( divGrid.innerHTML != ”  )
                    window.open( ”, ” ).document.write( divGrid.innerHTML + ‘<input type=”button” onclick=”window.print();” value=”Print”>’  );
            }
        </script>   
    </head>
    <body>
    <div id=”divGrid”>
        ”put your datagrid here to test
    </div>
    <input type=”button” value=”Click me” onclick=”showReport();” />
    </body>
</html>

Read Full Post »

Older Posts »