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%”>
<asp:DataList ID=”dlPhotos” Runat=”server” Width=”100%” ItemStyle-HorizontalAlign=”Left” RepeatLayout=”Table” RepeatDirection=”Horizontal” RepeatColumns=”4″ OnItemDataBound=”dlPhotos_ItemDataBound”>
<asp:Image id=”imgThumbnail” runat=”server” borderSize=”5″ />
<table width=”100%”>
<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>

Code for the pagination is:

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

thats just a sample, please customize it for your works


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”);



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


Read Full Post »

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


Read Full Post »

print a datagrid

        <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”>’  );
    <div id=”divGrid”>
        ”put your datagrid here to test
    <input type=”button” value=”Click me” onclick=”showReport();” />

Read Full Post »

Older Posts »