Click here to Skip to main content
12,076,925 members (47,282 online)
Rate this:
 
Please Sign up or sign in to vote.
Dropdownlist 1 =Doc no
Dropdownlist 2 = Doc title
Button = Add
Gridview=gridview1
Dropdown get data from sharepoint list.(use caml query)

doc no | doc title | add |

--------------------------

grid view1


--------------------------

How to delete row that i have added in gridview?


this my code:

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] = DropDownList1.Text;
 
               dr[1] = DropDownList2.Text;
 
               dt.Rows.Add(dr);
 
           }
 
           else
           {
 
               dr = dt.NewRow();
 
               dr[0] = DropDownList1.Text;
 
               dr[1] = DropDownList2.Text;
 
               dt.Rows.Add(dr);
 
           }
           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;
       }


for button add

protected void Button1_Click(object sender, EventArgs e)
       {
           if (ViewState["CurrentData"] != null)
           {
 
               DataTable dt = (DataTable)ViewState["CurrentData"];
 
               int count = dt.Rows.Count;
 
               BindGrid(count);
 
           }
 
           else
           {
 
               BindGrid(1);
 
           }



gridview:

<asp:GridView ID="GridView1" AutoGenerateDeleteButton="true" OnRowDeleting="GridView1_RowDeleting" runat="server" CssClass="datagridview">
                </asp:GridView>
Posted 13-Dec-12 21:12pm
Edited 13-Dec-12 21:17pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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

Solution 2

Hi,

Try this,

DataTable dt = new DataTable();
        dt = (DataTable)ViewState["CurrentData"];
 
        for(int i=0;i<dt.rows.count;i++)>
        {
            if (dt.Rows[i][0].ToString() == "Your value")
            {
                dt.Rows[i].Delete();
            }
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
        ViewState["CurrentData"] = dt;
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

me.validate()
me.remove.currentcell()
  Permalink  
v2
Comments
man_alansik 14-Dec-12 2:24am
   
thanks for helping ...
but i dont know where tu put your code ?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160212.1 | Last Updated 26 Jun 2014
Copyright © CodeProject, 1999-2016
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