Dynamically adding new row to grid view without postback

Posted by Deveder under ASP.NET on 6/30/2011 | Points: 10 | Views : 60530 | Status : [Member] | Replies : 6
How to add new row to gridview without postback in aspx page.




Responses

Posted by: Susanthampy on: 6/30/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

pls refer this link,

http://aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx

Regards,
Susan

Deveder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/30/2011 [Member] Starter | Points: 25

Up
0
Down
try this

http://aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx

Thanks&Regards
LakshmiNarayana Nalluri.

Deveder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 6/30/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Check this sample...

http://ashishmit99.wordpress.com/2011/05/26/gridview-updateeditdeleteadd-row-without-postback/

Thanks
Karthik
www.f5Debug.net

Deveder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sajeev_M87 on: 12/11/2012 [Member] Starter | Points: 25

Up
0
Down
private void setInitialRow_second()
{

DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));

dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;


dt.Rows.Add(dr);
ViewState["CurrentTable1"] = dt;
grd_description.DataSource = dt;
grd_description.DataBind();



}
private void addNewRowToGrid()
{

int rowIndex = 0;
if (ViewState["CurrentTable1"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable1"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
int i;
int c = grd_description.Rows.Count;
for (i = 1; i <= c; i++)
{

//extract the TextBox values
TextBox box1 = (TextBox)grd_description.Rows[rowIndex].Cells[1].FindControl("txt_contained");
TextBox box2 = (TextBox)grd_description.Rows[rowIndex].Cells[2].FindControl("txt_designcode");

drCurrentRow = dtCurrentTable.NewRow();

drCurrentRow["RowNumber"] = i + 1;
drCurrentRow["Column1"] = box1.Text;
drCurrentRow["Column2"] = box2.Text;


rowIndex++;
dtCurrentTable.Rows.Add(drCurrentRow);


}

ViewState["CurrentTable1"] = dtCurrentTable;
grd_description.DataSource = dtCurrentTable;
grd_description.DataBind();

DropDownList drp = (DropDownList)grd_description.Rows[i - 1].Cells[10].FindControl("drp_basedon");

}

}


//Set Previous Data on Postbacks

setPreviousData();

}

private void setPreviousData()
{

int rowIndex = 0;
if (ViewState["CurrentTable1"] != null)
{

DataTable dt = (DataTable)ViewState["CurrentTable1"];
if (dt.Rows.Count > 0)
{
for (int i = 1; i < dt.Rows.Count; i++)
{
TextBox box1 = (TextBox)grd_description.Rows[rowIndex].Cells[1].FindControl("txt_contained");
TextBox box2 = (TextBox)grd_description.Rows[rowIndex].Cells[2].FindControl("txt_designcode");



box1.Text = dt.Rows[i]["Column1"].ToString();
box2.Text = dt.Rows[i]["Column2"].ToString();

rowIndex++;

}
for (int ii = dt.Rows.Count - 1; ii >= 1; ii--)
{
dt.Rows.Remove(dt.Rows[ii]);
}

}

}

}


Deveder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Grovalmitch on: 8/6/2014 [Member] Starter | Points: 25

Up
0
Down
Add, Edit and delete from asp.net gridview..

http://asp.net-informations.com/gridview/gridview-operations.htm

groval

Deveder, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manimaddu on: 8/6/2014 [Member] Starter | Points: 25

Up
0
Down
Hi..
refer the below link.It will helpful to u.

http://www.nullskull.com/q/10103608/dynamically-adding-new-row-to-a-gridview-without-postback-and-ajex-update-panel.aspx

Thanks,
ManiKumar

Thanks & Regards,
Mani Kumar

Deveder, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response