Dropdownlist 1 =Doc no
Dropdownlist 2 = Doc title
Button = Add
Gridview=gridview1
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>
thanks for helping.