Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# sharepoint2010 , +
hello ,
1)I have 3 dropdown list and 1 datagridview and when we select the data in dropdown list and click add button, the data will add into data grid view.
2)Now my problem is I only can add data into data grid view.So , how to modify this code to add delete and reset button to delete slected row in datagrid view.
thank you for help.Smile | :)
 
 protected void BindGrid(int rowcount)
        {
 
            DataTable dt = new DataTable();
            DataRow dr;
            dt.Columns.Add(new System.Data.DataColumn("Document No",
typeof(String)));          
            dt.Columns.Add(new System.Data.DataColumn("Document Title", typeof(String)));
            dt.Columns.Add(new System.Data.DataColumn("Revision", typeof(String)));
            dt.Columns.Add(new System.Data.DataColumn("File", typeof(String)));
 
            if (ViewState["CurrentData"] != null)
            {
 
                for (int i = 0; i < rowcount + 1; i++)
                {
 
                    dt = (DataTable)ViewState["CurrentData"];
 
                    if (dt.Rows.Count > 0)
                    {
 
                        dr = dt.NewRow();
 
                        dr[0] = dt.Rows[0][0].ToString();
                    }
 
                }
 
                dr = dt.NewRow();
                dr[0] = DropDownList19.Text;            
                dr[1] = DropDownList21.Text;
                dr[2] = DropDownList20.Text;
                dt.Rows.Add(dr);
            }
 
            else
            {
 
                dr = dt.NewRow();
                dr[0] = DropDownList19.Text;
                dr[1] = DropDownList21.Text;
                dr[2] = DropDownList20.Text;
                dt.Rows.Add(dr);
            }
            // If ViewState has a data then use the value as the DataSource

            if (ViewState["CurrentData"] != null)
            {
 
                GridView1.DataSource = (DataTable)ViewState["CurrentData"];
 
                GridView1.DataBind();
 
            }
 
            else
            {
 
                // Bind GridView with the initial data assocaited in the DataTable

                GridView1.DataSource = dt;
 
                GridView1.DataBind();
            }
 
            // Store the DataTable in ViewState to retain the values

            ViewState["CurrentData"] = dt;
        }
//////////////////////////add button//////////////////////////////////

        protected void Button1_Click(object sender, EventArgs e)
        {
            // Check if the ViewState has a data assoiciated within it. If 

            if (ViewState["CurrentData"] != null)
            {
 
                DataTable dt = (DataTable)ViewState["CurrentData"];
 
                int count = dt.Rows.Count;
 
                BindGrid(count);
 
            }
 
            else
            {
 
                BindGrid(1);
            }
 
            DropDownList4.Text = string.Empty;
            DropDownList4.Focus();
            {
 
                string uploadedFilePath = @"C:\";
                string sharePointListPath = "http://path/";
 
                if (FileUpload1.HasFile)
                    try
                    {
                        FileUpload1.SaveAs(
                            uploadedFilePath + FileUpload1.FileName);
 
                        errorlabaelupload.Text = "File name: " +
                             FileUpload1.PostedFile.FileName + "<br>" +
                             FileUpload1.PostedFile.ContentLength + " bytes<br>" +
                             "Content type: " +
                             FileUpload1.PostedFile.ContentType;
 
                        UploadFileToSharePoint(
                            uploadedFilePath + FileUpload1.FileName,
                            sharePointListPath + FileUpload1.FileName);
                    }
                    catch (Exception ex)
                    {
                        errorlabaelupload.Text = "ERROR: " + ex.Message.ToString();
                    }
                else
                {
                    errorlabaelupload.Text = "You have not specified a file.";
                }
            }
 

        }
 
    }
}
Posted 13-Nov-12 6:06am
Edited 13-Nov-12 10:49am
ridoy51.9K
v2
Comments
Christian Graus at 13-Nov-12 11:09am
   
This is just a code dump, not a clear focused question.
xalanxic at 13-Nov-12 11:12am
   
actually i want to delete row that was add into datagrid view.selected row will deleted when i click delete button.
Christian Graus at 13-Nov-12 11:16am
   
http://www.codeproject.com/Questions/291582/adding-a-col-which-contains-a-delete-button-for-ea - found this with google, but the site lets you search previous answers, too
xalanxic at 13-Nov-12 11:29am
   
thanks ...

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
See my article if could help...
 
Delete record in DatagridView?
 
Regards,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100