0

Hi all i have a form of data. each save button click ,I need to change in DataTable.

protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("1"), new DataColumn("2"), new DataColumn("3")});
        dt.Rows.Add( 1.Text, 2.Text, 3.Text);
}

currently last button click data only storing in data table . how can I store all the button save data to this data table ?

1 Answer 1

2

I don't think that is good way but work :

    public static DataTable dt = new DataTable() { Columns = { new DataColumn("1"), new DataColumn("2"), new DataColumn("3") } };
    protected void OnClick(object sender, EventArgs e)
    {
        dt.Rows.Add("1", "1", "1");
        var count = dt.Rows.Count;
    }

Result: enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

still only last added row in dt.rows bro .
@xyz Updated my Answer and add Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.