Sunday, March 11, 2012

How to show message box with update panel in asp.net


 ScriptManager.RegisterStartupScript(TxtMobileNumber,typeof(Page), "Open Window", "alert('Mobile Number Already Exists')", true);

Saturday, March 10, 2012

GET LATEST INDEX OF CHECKBOX LIST


  string lastValue = string.Empty;
    int lastIndex=0;

        foreach (ListItem listitem in chkSec.Items)
        {
            if (listitem.Selected)
            {
                int thisIndex = chkSec.Items.IndexOf(listitem);

                if (lastIndex < thisIndex)
                {
                    lastIndex = thisIndex;
                    lastValue = listitem.Value;
                }
            }
        }

Thursday, June 16, 2011

How to calculate difference between two date in ASP.NET with C#


         TimeSpan tspan;
         DateTime date1 = Convert.ToDateTime(txtDateFrom.Text);
         DateTime date2 = Convert.ToDateTime(txtDateTo.Text);
         if (date1 > date2)
             tspan = date1.Subtract(date2);
         else
             tspan = date2.Subtract(date1);
         int days = Convert.ToInt32(tspan.TotalDays);

How to get first day of month in ASP.NET

DateTime date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

Monday, May 30, 2011

Data Format String For GRID VIEW







Format character

Description

Example

d

Short date pattern.

Format: {0:d}

6/15/2009 1:45:30 PM -> 6/15/2009

D

Long date pattern.

Format: {0:D}

6/15/2009 1:45:30 PM ->Monday, June 15, 2009

f

Full date/time pattern (short time).

Format: {0:f}

6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45 PM

F

Full date/time pattern (long time).

Format: {0:F}

6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45:30 PM

g

General date/time pattern (short time).

Format: {0:g}

6/15/2009 1:45:30 PM -> 6/15/2009 1:45 PM

G

General date/time pattern (long time).

Format: {0:G}

6/15/2009 1:45:30 PM -> 6/15/2009 1:45:30 PM

M or m

Month/day pattern.

Format: {0:M}

6/15/2009 1:45:30 PM -> June 15

O or o

Round-trip date/time pattern.

Format: {0:o}

6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000

R or r

RFC1123 pattern .

Format: {0:R}

6/15/2009 1:45:30 PM -> Mon, 15 Jun 2009 20:45:30 GMT

s

Sortable date/time pattern.

Format: {0:s}

6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30

t

Short time pattern.

Format: {0:t}





Sunday, May 29, 2011

How to create dynamic GRID VIEW in asp.net


public void loaddynamicgrid()
{
       DataTable dt = new DataTable();
        DataColumn dc;
        DataRow  dRow;


        dc = new DataColumn("Date", typeof(DateTime));
        dt.Columns.Add(dc);

     
        dc = new DataColumn("Name", typeof(Int64));
        dt.Columns.Add(dc);
     
       SqlDataAdapter da = new SqlDataAdapter("select * from Tbl_Emp", Sqlconnectionstring);
      DataSet  ds = new DataSet();
        da.Fill(ds);

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
         
            dRow = dt.NewRow();
            dt.Rows.Add(dRow);
            dt.Rows[i][0] = ds.Tables[0].Rows[i]["date"].ToString();
 
            dt.Rows[i][1] = ds.Tables[0].Rows[i]["name"].ToString();


          }

         }

How to add dynamic footer in dynamic Grid View with ASP.NET


This code use after Binding a  gridview.

        GridViewRow footerRow = GridView1.FooterRow;
        Label lbl = new Label();
        lbl.Text = "Create Footer Row";
        footerRow.Cells[2].Controls.Add(lbl);