Muhammad Nasir Khan
Muhammad Nasir Khan

Reputation: 59

How to read data of a selected Cell of a Table and Update it in C#

I am working on creating a table and inserting data into it (it is not a sql database table it is ASP.NET table) Now the problem is i want to update just one column of the table I want to change data of just one or more cells of that columns Can you help me please how to do this

for (int i = 0; i < hfc.Count; i++)
                {
                    TableRow NewRow1 = new TableRow();

                    NewCell1 = new TableCell();
                    NewCell2 = new TableCell();
                    NewCell3 = new TableCell();
                    NewCell4 = new TableCell();
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        Label no = new Label();
                        Label batch = new Label();
                        Label status = new Label();
                        Label name = new Label();
                        no.Text = (number++).ToString();
                        NewCell1.Controls.Add(no);
                        NewRow1.Cells.Add(NewCell1);

                        name.Text = (hpf.FileName).ToString();
                        NewCell2.Controls.Add(name);
                        NewRow1.Cells.Add(NewCell2);

                        batch.Text = ("00" + (i+1)).ToString();
                        NewCell3.Controls.Add(batch);
                        NewRow1.Cells.Add(NewCell3);

                        //status.Text = ("In Progress").ToString();
                        //NewCell4.Controls.Add(status); 
                        NewCell4.Text = "In Progress";
                        NewCell4.ID = "status";
                        NewRow1.Cells.Add(NewCell4);

                        Table1.Rows.Add(NewRow1);

                    }
                }

Upvotes: 2

Views: 1081

Answers (1)

Steve Wellens
Steve Wellens

Reputation: 20640

Are you looking for this?

 Table1.Rows[3].Cells[3].Text = "Hello World";

Remember, if you want the table to persist between postbacks, YOU will have to decide how to maintain it's state or rebuild it each time.

[Edit]

Here is a complete sample to show you that it works:

<asp:Table ID="Table1" runat="server">

protected void Page_Load(object sender, EventArgs e)
{
    for (int RowIndex = 0; RowIndex < 4; RowIndex++)
    {
        TableRow NewRow = new TableRow();

        for (int ColumnIndex = 0; ColumnIndex < 4; ColumnIndex++)
        {
            TableCell NewCell = new TableCell();
            NewCell.Text = "aaa";
            NewRow.Cells.Add(NewCell);
        }
        Table1.Rows.Add(NewRow);
    }

    Table1.Rows[3].Cells[3].Text =  "Hello World!";
}

Upvotes: 2

Related Questions