adding row to gridview on buton click

i have three textbox and a button...i want to add row to gridview on button click...and put values of textbox n gridview textbox....
eg.. i have 3 texboxs t1,t2,t3 and button b
on button click b...
add text of t1 to gridview cell[0] ,t2 text to gridview cell[1]. t3 text to gridview[2]...

and one thing more i don't wanna replace any row..

on one button click 1st row will be added
on 2nd button click 2nd row will be added.. so .on..

then i am gonna save all values to database...
exploit344Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RiteshShahCommented:
0
exploit344Author Commented:
DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            dt = new DataTable();
            MakeDataTable();
        }
        else
        {
            dt = (DataTable)ViewState["DataTable"];
        }
        ViewState["DataTable"] = dt;
    }

    private void MakeDataTable()
    {
        dt.Columns.Add("Name");
        dt.Columns.Add("Number");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        AddToDataTable();
        BindGrid();
    }

    private void AddToDataTable()
    {
        DataRow dr = dt.NewRow();
        dr["Name"] = txtName.Text;
        dr["Number"] = txtNumber.Text;
        dt.Rows.Add(dr);
    }

    private void BindGrid()
    {
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }


this code is working fine.. but this is for simple gridview..
i mean i have textbox in gridview.. now how do i put values of textbox above gridview in to textbox...

cause at last i have to save gridview into table.. so my prob is i have textbox in gridview.. so can u please modify this code according to textbox inside gridview.. i mean insert values to gridview textbox
0
mahajan344Commented:
just put this code to save button..
foreach(GridViewRow row in GridView1.Rows)
        {
            string st = row.Cells[0].Text;
            string st1 = row.Cells[1].Text;
                cmd = new SqlCommand("insert into t1(first,second)values(@first,@second)", con);
                cmd.Parameters.AddWithValue("@first",st);
                cmd.Parameters.AddWithValue("@second", st1);
                cmd.ExecuteNonQuery();
           
        }

u don't need a textbox or label.. its working fine..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
exploit344Author Commented:
thnx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.