Click here to Skip to main content
15,029,206 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add three fields which of ( country name,language name and description )..
and a "add button" to add the fields in design page only using table or grid.If i click another button i.e "save button" that all the rows created are should be stored in sql server 2005..

I had made 30% of it now i can add a single row.if i tried to add multiple row it's overriding.I can able identify the reason but unable to solve.. Plz help me to complete this process...


Here my code's

C#
protected void lnkbtnAddRow_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();

DataColumn[] columns = { new DataColumn("Country", System.Type.GetType("System.String")), new DataColumn("Language", System.Type.GetType("System.String")), new DataColumn("Description", System.Type.GetType("System.String")) };

        dt.Columns.AddRange(columns);
        DataRow dr;

        dr = dt.NewRow();
        dr[0] = ddlCountry.SelectedValue;
        dr[1] = ddlLanguage.SelectedValue;
        dr[2] = txtDescription.Text;
        dt.Rows.Add(dr);

        GVaddrow.DataSource = dt;
        GVaddrow.DataBind();
}
protected void lnkbtnSave_Click(object sender, EventArgs e)
{

}

Thanks in advance...
Posted

C#
protected void lnkbtnAddRow_Click(object sender, EventArgs e)
{
if(Session["Data"]==null)
{
DataTable dt = new DataTable();
 
DataColumn[] columns = { new DataColumn("Country", System.Type.GetType("System.String")), new DataColumn("Language", System.Type.GetType("System.String")), new DataColumn("Description", System.Type.GetType("System.String")) };
dt.Columns.AddRange(columns);
}
else
{
 DataTable dt=(DataTable)Session["Data"];
}
 
        
        DataRow dr;
 
        dr = dt.NewRow();
        dr[0] = ddlCountry.SelectedValue;
        dr[1] = ddlLanguage.SelectedValue;
        dr[2] = txtDescription.Text;
        dt.Rows.Add(dr);
        Session["Data"]=dt;
        GVaddrow.DataSource = dt;
        GVaddrow.DataBind();
}

Try this...It should work...

Regards
Dinesh Kumar.V.
   
Comments
SViki 2-Apr-14 5:24am
   
Thank you so much..

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900