insert the data using detailview


    i m using a grid view and a detailsview, i want to inserrt the data in gridview using detailsview.. i got the details view with insert button when click on it does't work. the is —> 

public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart
         GridView _view = new GridView();
        SqlDataSource ds = new SqlDataSource();
        DetailsView dv = new DetailsView();
        protected override void CreateChildControls()

            _view.ID= "Grid1";
            _view.GridLines = GridLines.None;
            _view.AutoGenerateColumns = true;
            _view.DataKeyNames = new string[] { "id" };               
            CommandField field = new CommandField();                        
            field.ShowDeleteButton = true;                    
            field.ShowEditButton = true;
            ds.ID = "_authorsDS";           
            ds.ConnectionString = "server=ie10dt2k3955zl1;database=anupam;uid=webuser;pwd=Password2";
            ds.SelectCommand = "select * from ToDoList";
            ds.UpdateCommand = "update ToDoList set tasklist=@tasklist where id=@id";
            ds.UpdateParameters.Add("@tasklist", "");
            ds.UpdateParameters.Add("@id", "");
            ds.DeleteCommand = "delete from ToDoList where id=@id";                  
            dv.ID = "dv1";
            dv.DataKeyNames = new string[] { "id" };            
            dv.DefaultMode = DetailsViewMode.Insert;
            dv.AutoGenerateInsertButton = true;          
            dv.ItemInserting+=new DetailsViewInsertEventHandler(dv_ItemInserting);
            dv.ItemInserted+=new DetailsViewInsertedEventHandler(dv_ItemInserted);
            dv.DataSource = ds.ID;
            _view.DataSourceID = ds.ID; 

        void dv_ItemInserting(object sender, DetailsViewInsertEventArgs e)
            _view.DataSourceID = ds.ID;

            ds.ConnectionString = "server=ie10dt2k3955zl1;database=anupam;uid=webuser;pwd=Password2";
            ds.DeleteCommand = "delete from ToDoList where id=@id2";


        void dv_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
            _view.DataSourceID = ds.ID;

 plz tell wht changes should be made to work this…



Read More


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s