<ISWebGrid:WebGrid ID="WebGrid1" DataCacheStorage="PageCache"
                DefaultStyleMode="Win7"  runat="server" 
                Height="148px" UseDefaultStyle="True"
                Width="329px"              
                oninitializedatasource="WebGrid1_InitializeDataSource"               
                onpreparedatabinding="WebGrid1_PrepareDataBinding"
                onaddrow="WebGrid1_AddRow" ondeleterow="WebGrid1_DeleteRow"
                onupdaterow="WebGrid1_UpdateRow"
                oninitializepostback="WebGrid1_InitializePostBack" >
               <LayoutSettings   NewRowLostFocusAction="AlwaysUpdate" AllowEdit="Yes" AllowDelete="Yes"  PagingMode="VirtualLoad" VirtualPageSize="13">
                <ClientSideEvents   OnEditKeyDown="WebGrid1_OnEditKeyDown" />
                </LayoutSettings>         
       </ISWebGrid:WebGrid>






















public partial class insertRowToSql : System.Web.UI.Page
{
   string sqlcon = System.Configuration.ConfigurationManager.ConnectionStrings["loginConnectionString2"].ToString();
   SqlConnection conn;
   SqlDataAdapter da;
   DataSet sqlds;
   SqlCommandBuilder builder;
   protected void Page_Load(object sender, EventArgs e)
    {       
        Cache["temp"] = "false";
        conn= new SqlConnection(sqlcon);
        da = new SqlDataAdapter("SELECT  id ,name ,pwd FROM  logintbl;", conn);
        builder= new SqlCommandBuilder(da);  
    }
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.           DataSourceEventArgs e)
    {
        WebGrid1.RootTable.DataKeyField = "id"; //set primary key     
WebGrid1.RetrieveStructure();       
WebGrid1.RootTable.DataKeyField = "id";  
     
    }





//insert
protected void WebGrid1_AddRow(object sender, RowEventArgs e){DataSet ds = (DataSet)WebGrid1.DataSource; da.InsertCommand = builder.GetInsertCommand(); da.Update(ds); e.ReturnValue = false; WebGrid1.ClientAction.Refresh(); }
//update
protected void WebGrid1_UpdateRow(object sender, RowEventArgs e) { DataSet dt = (DataSet)WebGrid1.GetCachedDataSource(); DataSet changeDT = (DataSet)dt.GetChanges(); da.UpdateCommand = builder.GetUpdateCommand(); da.Update(changeDT); e.ReturnValue = false; }
//delete
protected void WebGrid1_DeleteRow(object sender, RowEventArgs e) { DataSet ds = (DataSet)WebGrid1.DataSource; da.DeleteCommand = builder.GetDeleteCommand(); ((DataRowView)e.Row.DataRow).Row.Delete(); da.Update(ds); e.ReturnValue = false; WebGrid1.ClientAction.Refresh(); }