Wednesday, July 24, 2013

How to delete all the tables in a Databse MS SQL Server

Use the following query to delete the constraints and the schema of the table.
Note: with out Remove the constraints you are unable to delete the table.
DECLARE @table_schema varchar(100)
       ,@table_name varchar(100)
       ,@constraint_schema varchar(100)
       ,@constraint_name varchar(100)
       ,@cmd nvarchar(200)
  
  
--
-- drop all the constraints
--
DECLARE constraint_cursor CURSOR FOR
  select CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_SCHEMA, TABLE_NAME
    from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
   where TABLE_NAME != 'sysdiagrams'
    order by CONSTRAINT_TYPE asc -- FOREIGN KEY, then PRIMARY KEY
       
  
OPEN constraint_cursor
FETCH NEXT FROM constraint_cursor INTO @constraint_schema, @constraint_name, @table_schema, @table_name
  
WHILE @@FETCH_STATUS = 0
BEGIN
     SELECT @cmd = 'ALTER TABLE [' + @table_schema + '].[' + @table_name + '] DROP CONSTRAINT [' + @constraint_name + ']'
     --select @cmd
     EXEC sp_executesql @cmd
  
     FETCH NEXT FROM constraint_cursor INTO @constraint_schema, @constraint_name, @table_schema, @table_name
END
  
CLOSE constraint_cursor
DEALLOCATE constraint_cursor
  
  
  
--
-- drop all the tables
--
DECLARE table_cursor CURSOR FOR
  select TABLE_SCHEMA, TABLE_NAME
    from INFORMATION_SCHEMA.TABLES
   where TABLE_NAME != 'sysdiagrams'
  
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @table_schema, @table_name
  
WHILE @@FETCH_STATUS = 0
BEGIN
     SELECT @cmd = 'DROP TABLE [' + @table_schema + '].[' + @table_name + ']'
     --select @cmd
     EXEC sp_executesql @cmd
  
  
     FETCH NEXT FROM table_cursor INTO @table_schema, @table_name
END
  
CLOSE table_cursor
DEALLOCATE table_cursor

Thursday, June 13, 2013

How to use user-Defined Function

CREATE FUNCTION [dbo].[GenerateIntegers] ( @MaxValue INT )
RETURNS @Integers TABLE ( [IntValue] INT )
AS
BEGIN
    DECLARE @Index    INT
    SET @Index = 0
    WHILE @Index <= @MaxValue
    BEGIN
        INSERT INTO @Integers ( [IntValue] ) VALUES ( @Index )
        SET @Index = @Index + 1
    END

    RETURN
END
GO


Description

The user-defined function is quite straight-forward.  It simply inserts into the return TABLE variable (@Integers) the integer values from 1 to the maximum integer value supplied in the parameter using a WHILE loop.  If the value supplied in the parameter is less than 1, then the table returned will not contain any records.

To use this function, you can simply issue a simple SELECT statement and using this in the FROM clause of the SELECT, as follows:

SELECT * FROM [dbo].[GenerateIntegers] ( 1001 )

Tuesday, June 11, 2013

List of Free SEO Friendly Directories

http://21stguru.com    
http://addalinkdirectory.com    
http://bestsubmitdirectory.com
http://carefullypicked.com    
http://directorycave.com    
http://directpr.org    
http://dirtree.com    
http://elektronickits.com    
http://fastfiredirectory.com    
http://featuredinc.com    
http://freedofollowdirectory.org    
http://freelanddirectory.com    
http://gainesvillesbest.com    
http://glitterdirectory.com    
http://intermagnetusa.org    
http://links.kozolec.net    
http://m-directory.com    
http://masterseodirectory.com    
http://myonlinewebdirectory.org    
http://online-web-directory.com    
http://prboostdirectory.com    
http://reppinbelizean.com    
http://reservelinks.info    
http://searchwebdirectory.net    
http://shamrockdirectory.com




Note: More information visit: http://www.directorymaximizer.com/seo-friendly-directories.php

Sunday, June 09, 2013

Server Error -- System.Web.HttpException: Unable to validate data.

use machine key under system.web in web.config file to rectify this error

<system.web>
    <machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="3DES" decryption="3DES"/>
</system.web>

Tuesday, May 21, 2013

How to send Messages using asp.net with help of way2sms

protected override void Page_Load(object sender, System.EventArgs e)
        {
            HttpUtility.UrlEncode("SMS");
            string API = "http://www.way2sms.com/jsp/InstantSMS.jsp?UID=9942676484&PWD=password&MSG=Hello+yyy+zzz&MobileNumber=9942676484";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            Response.Write(reader.ReadToEnd());
        }

 Note: Please Register with way2sms.com before try this Coding. Registeration in Way2sms is mandatory.
                           *********************************

Tuesday, May 14, 2013

How to get date between two Dates in a month


How to show date (mm/dd/yyyy) between two dates
_______________________________________________
declare @dateh table(ind int identity(1,1),date1 smalldatetime,date2 smalldatetime)

insert into @dateh select '1/1/2011','1/15/2011'


;with T as
(
    select date1,date2 from @dateh as d
    union all
    select dateadd(dd,1,date1),date2 From T
    where  dateadd(dd,1,date1)<= date2
)
Select date1 from T








Tuesday, February 05, 2013

how to send sms from asp.net with c# using way2sms

C# Coding

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;


public partial class _Default : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
    string mbno, mseg, ckuser, ckpass;
    private HttpWebRequest req;
    private CookieContainer cookieCntr;
    private string strNewValue;
    public static string responseee;
    private HttpWebResponse response;


    protected void Page_Load(object sender, EventArgs e)
    {
        //connect();
        if (!(IsPostBack))
        {          
            btnsend.Attributes.Add("onclick", "return Validate('" + txttono.ClientID + "','" + txtmsg.ClientID + "');");
           
        }
    }

   

   
    protected void btnsend_Click(object sender, EventArgs e)
    {        
    //    try
    //    {
    //        Session["id"] = txtuname.Text;
    //        Session["pw"] = txtpwd.Text;
    //        mbno = txttono.Text;
    //        mseg = txtmsg.Text;

    //        connect();
    //        sendSms(mbno, mseg);
    //        txttono.Text = "";
    //        txtmsg.Text = "";
    //    }
    //    catch (Exception ex)
    //    {
    //        lblError.Text = ex.Message;
    //        lblError.Visible = true;
    //    }
        try
        {

            send(txtuname.Text, txtpwd.Text, txtmsg.Text, txttono.Text);
            Response.Write("Message sent successfully....");
        }
        catch
        {
            Response.Write("Error Occured!!!");
        }
    }

    public void send(string uid, string password, string message, string no)
    {
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=way2sms");
        HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
        System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
        string responseString = respStreamReader.ReadToEnd();
        respStreamReader.Close();
        myResp.Close();
    }


    public void connect()
    {
        ckuser = Session["id"].ToString();
        ckpass = Session["pw"].ToString();

        try
        {
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");

            this.req.CookieContainer = new CookieContainer();
            this.req.AllowAutoRedirect = false;
            this.req.Method = "POST";
            this.req.ContentType = "application/x-www-form-urlencoded";
            this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
            this.req.ContentLength = this.strNewValue.Length;
            StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
            writer.Write(this.strNewValue);
            writer.Close();
            this.response = (HttpWebResponse)this.req.GetResponse();
            this.cookieCntr = this.req.CookieContainer;
            this.response.Close();
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
            this.req.CookieContainer = this.cookieCntr;
            this.req.Method = "GET";
            this.response = (HttpWebResponse)this.req.GetResponse();
            responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
            int index = Regex.Match(responseee, "custf").Index;
            responseee = responseee.Substring(index, 0x12);
            responseee = responseee.Replace("\"", "").Replace(">", "").Trim();
            this.response.Close();           
            lblError.Text = "connected";
        }
        catch (Exception)
        {
            lblError.Text = "Error connecting to the server...";
            Session["error"] = "Error connecting to the server...";
        }
    }

    public void sendSms(string mbno, string mseg)
    {
        if ((mbno != "") && (mseg != ""))
        {
            try
            {
                this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//FirstServletsms?custid=");
                this.req.AllowAutoRedirect = false;
                this.req.CookieContainer = this.cookieCntr;
                this.req.Method = "POST";
                this.req.ContentType = "application/x-www-form-urlencoded";
                this.strNewValue = "custid=undefined&HiddenAction=instantsms&Action=" + responseee + "&login=&pass=&MobNo=" + this.mbno + "&textArea=" + this.mseg;

                string msg = this.mseg;
                string mbeno = this.mbno;

                this.req.ContentLength = this.strNewValue.Length;
                StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
                writer.Write(this.strNewValue);
                writer.Close();
                this.response = (HttpWebResponse)this.req.GetResponse();

                this.response.Close();
                lblError.Text = "Message Sent..... " + mbeno + ": " + msg;
            }
            catch (Exception)
            {
                lblError.Text = "Error Sending msg....check your connection...";
            }
        }
        else
        {
            lblError.Text = "Mob no or msg missing";
        }
    }

    //protected void btnclr_Click(object sender, EventArgs e)
    //{
    //    //txtuname.Text = "";
    //    //txtpwd.Text = "";
    //    //txttono.Text = "";
    //    //txtmsg.Text = "";
    //}
}

Dynamically add and delete rows in gridview using asp.net with c#

 .aspx coding

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Using_Gridview_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Using DataGridview</title>
    <link href="Css/StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color:Gray">
   
  
    <form id="form1" runat="server">
   <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <center>
   
    <div id="div1" class="divclass">
        <asp:Label ID="Label1" runat="server" Text="Add new Users"></asp:Label><br />
        <asp:GridView ID="grvStudentDetails" runat="server"
                ShowFooter="True" AutoGenerateColumns="False"
                CellPadding="4" ForeColor="#333333"
                GridLines="None"           
            onrowdeleting="grvStudentDetails_RowDeleting">
    <Columns>
        <asp:BoundField DataField="RowNumber" HeaderText="SNo" />
        <asp:TemplateField HeaderText="Student Name">
            <ItemTemplate>
                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student Age">
            <ItemTemplate>
                <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student Address">
            <ItemTemplate>
                <asp:TextBox ID="txtAddress" runat="server"
                   Height="55px" TextMode="MultiLine"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Gender">
            <ItemTemplate>
                <asp:RadioButtonList ID="RBLGender"
                           runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Value="M">Male</asp:ListItem>
                    <asp:ListItem Value="F">Female</asp:ListItem>
                </asp:RadioButtonList>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Qualification">
            <ItemTemplate>
                <asp:DropDownList ID="drpQualification" runat="server">
                              <asp:ListItem Value="0" Selected="True">--Select--</asp:ListItem>
                              <asp:ListItem>Admin</asp:ListItem>
                              <asp:ListItem>User</asp:ListItem>
                </asp:DropDownList>
            </ItemTemplate>
            <FooterStyle HorizontalAlign="Right" />
            <FooterTemplate>
                <asp:Button ID="ButtonAdd" runat="server"
                        Text="AddNewRow" OnClick="ButtonAdd_Click"/>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowDeleteButton="True" />
    </Columns>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#EFF3FB" />
    <EditRowStyle BackColor="#2461BF" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>
    </div>
    </center>
    <center>
                <asp:Button ID="btnSave" runat="server" Text="Save Data"
                    onclick="btnSave_Click"/>
                    &nbsp;<asp:Button ID="btnclear" runat="server" Text="Clear Data"
                    onclick="btnclear_Click"/>
                   
            </center>
   
    </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

C# coding

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

public partial class Using_Gridview_Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            FirstGridViewRow();
            //bindata();
        }       
    }

    private void FirstGridViewRow()
    {
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Col1", typeof(string)));
        dt.Columns.Add(new DataColumn("Col2", typeof(string)));
        dt.Columns.Add(new DataColumn("Col3", typeof(string)));
        dt.Columns.Add(new DataColumn("Col4", typeof(string)));
        dt.Columns.Add(new DataColumn("Col5", typeof(string)));
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Col1"] = string.Empty;
        dr["Col2"] = string.Empty;
        dr["Col3"] = string.Empty;
        dr["Col4"] = string.Empty;
        dr["Col5"] = string.Empty;
        dt.Rows.Add(dr);
        bindata();
        ViewState["CurrentTable"] = dt;
        grvStudentDetails.DataSource = dt;
        grvStudentDetails.DataBind();
    }

    private void bindata()
    {
        try
        {
            DropDownList bindlist;
            con.Open();
            string fetch_quer = "select role,rolename from user_login";
            SqlDataAdapter da = new SqlDataAdapter(fetch_quer, con);
            DataSet ds = new DataSet();
            da.Fill(ds);      

            foreach (GridViewRow grdrow in grvStudentDetails.Rows)
            {
                bindlist = (DropDownList)(grvStudentDetails.Rows[grdrow.RowIndex].Cells[5].FindControl("drpQualification"));
                bindlist.DataSource = ds;
                bindlist.DataValueField = "role";
                bindlist.DataTextField = "rolename";
                bindlist.DataBind();
            }
        }
        catch (Exception err)
        {
            Response.Write(err.Message);
        }
        finally
        {
            con.Close();
        }
        //SetPreviousData();
    }

    protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        AddNewRow();
    }

    private void AddNewRow()
    {
        int rowIndex = 0;

        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            if (dtCurrentTable.Rows.Count > 0)
            {
                for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                {
                    TextBox TextBoxName = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtName");
                    TextBox TextBoxAge = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[2].FindControl("txtAge");
                    TextBox TextBoxAddress =
                      (TextBox)grvStudentDetails.Rows[rowIndex].Cells[3].FindControl("txtAddress");
                    RadioButtonList RBLGender =
                      (RadioButtonList)grvStudentDetails.Rows[rowIndex].Cells[4].FindControl("RBLGender");
                    DropDownList DrpQualification =
                      (DropDownList)grvStudentDetails.Rows[rowIndex].Cells[5].FindControl("drpQualification");
                    drCurrentRow = dtCurrentTable.NewRow();
                    drCurrentRow["RowNumber"] = i + 1;

                    dtCurrentTable.Rows[i - 1]["Col1"] = TextBoxName.Text;
                    dtCurrentTable.Rows[i - 1]["Col2"] = TextBoxAge.Text;
                    dtCurrentTable.Rows[i - 1]["Col3"] = TextBoxAddress.Text;
                    dtCurrentTable.Rows[i - 1]["Col4"] = RBLGender.SelectedValue;
                    dtCurrentTable.Rows[i - 1]["Col5"] = DrpQualification.SelectedValue;
                    rowIndex++;
                }
                dtCurrentTable.Rows.Add(drCurrentRow);
                ViewState["CurrentTable"] = dtCurrentTable;
                grvStudentDetails.DataSource = dtCurrentTable;
                grvStudentDetails.DataBind();
            }
        }
        else
        {
            Response.Write("ViewState is null");
        }
        SetPreviousData();
    }

    private void SetPreviousData()
    {
        int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentTable"];
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TextBox TextBoxName = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtName");
                    TextBox TextBoxAge = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[2].FindControl("txtAge");
                    TextBox TextBoxAddress = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[3].FindControl("txtAddress");
                    RadioButtonList RBLGender = (RadioButtonList)grvStudentDetails.Rows[rowIndex].Cells[4].FindControl("RBLGender");
                    DropDownList DrpQualification = (DropDownList)grvStudentDetails.Rows[rowIndex].Cells[5].FindControl("drpQualification");

                    TextBoxName.Text = dt.Rows[i]["Col1"].ToString();
                    TextBoxAge.Text = dt.Rows[i]["Col2"].ToString();
                    TextBoxAddress.Text = dt.Rows[i]["Col3"].ToString();
                    RBLGender.SelectedValue = dt.Rows[i]["Col4"].ToString();
                    DrpQualification.SelectedValue = dt.Rows[i]["Col5"].ToString();
                    rowIndex++;
                }
            }
        }
    }
    private void SetRowData()
    {
        int rowIndex = 0;

        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            if (dtCurrentTable.Rows.Count > 0)
            {
                for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                {
                    TextBox TextBoxName = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtName");
                    TextBox TextBoxAge = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[2].FindControl("txtAge");
                    TextBox TextBoxAddress = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[3].FindControl("txtAddress");
                    RadioButtonList RBLGender = (RadioButtonList)grvStudentDetails.Rows[rowIndex].Cells[4].FindControl("RBLGender");
                    DropDownList DrpQualification = (DropDownList)grvStudentDetails.Rows[rowIndex].Cells[5].FindControl("drpQualification");
                    drCurrentRow = dtCurrentTable.NewRow();
                    drCurrentRow["RowNumber"] = i + 1;
                    dtCurrentTable.Rows[i - 1]["Col1"] = TextBoxName.Text;
                    dtCurrentTable.Rows[i - 1]["Col2"] = TextBoxAge.Text;
                    dtCurrentTable.Rows[i - 1]["Col3"] = TextBoxAddress.Text;
                    dtCurrentTable.Rows[i - 1]["Col4"] = RBLGender.SelectedValue;
                    dtCurrentTable.Rows[i - 1]["Col5"] = DrpQualification.SelectedValue;
                    rowIndex++;
                }

                ViewState["CurrentTable"] = dtCurrentTable;              
            }
        }
        else
        {
            Response.Write("ViewState is null");
        }
        //SetPreviousData();
    }


  
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string txName,txAdd,rbGen,drpQual;
        int txAge;
        try
        {
            SetRowData();
            DataTable table = ViewState["CurrentTable"] as DataTable;
           
            if (table != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    txName = row.ItemArray[1] as string;
                    txAge = Convert.ToInt32(row.ItemArray[2] as string);
                    txAdd = row.ItemArray[3] as string;
                    rbGen = row.ItemArray[4] as string;
                    drpQual = row.ItemArray[5] as string;
                  
                    string insert_query="insert into student_details values ('" + txName + "'," + txAge + ",'" + txAdd + "','" + rbGen + "','" + drpQual + "')";
                    con.Open();
                    try
                    {
                        SqlCommand cmd = new SqlCommand(insert_query, con);
                        cmd.ExecuteNonQuery();
                        FirstGridViewRow();
                    }
                    catch (Exception err)
                    {
                        Response.Write(err.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
    protected void grvStudentDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SetRowData();
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            int rowIndex = Convert.ToInt32(e.RowIndex);
            if (dt.Rows.Count > 1)
            {
                dt.Rows.Remove(dt.Rows[rowIndex]);
                drCurrentRow = dt.NewRow();
                ViewState["CurrentTable"] = dt;
                grvStudentDetails.DataSource = dt;
                grvStudentDetails.DataBind();

                for (int i = 0; i < grvStudentDetails.Rows.Count - 1; i++)
                {
                    grvStudentDetails.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                }
                SetPreviousData();
            }
        }
    }
    protected void btnclear_Click(object sender, EventArgs e)
    {
        FirstGridViewRow();
    }
}