C# 如何读取表中选定单元格的数据并在C中进行更新#
我正在创建一个表并将数据插入其中(它不是sql数据库表,而是ASP.NET表) 现在的问题是我只想更新表中的一列 我只想更改该列的一个或多个单元格的数据 你能帮我怎么做吗C# 如何读取表中选定单元格的数据并在C中进行更新#,c#,asp.net,C#,Asp.net,我正在创建一个表并将数据插入其中(它不是sql数据库表,而是ASP.NET表) 现在的问题是我只想更新表中的一列 我只想更改该列的一个或多个单元格的数据 你能帮我怎么做吗 for (int i = 0; i < hfc.Count; i++) { TableRow NewRow1 = new TableRow(); NewCell1 = new TableCell();
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);
}
}
for(int i=0;i0)
{
标签号=新标签();
标签批次=新标签();
标签状态=新标签();
标签名称=新标签();
no.Text=(number++).ToString();
NewCell1.Controls.Add(否);
NewRow1.Cells.Add(NewCell1);
name.Text=(hpf.FileName).ToString();
NewCell2.Controls.Add(名称);
NewRow1.Cells.Add(NewCell2);
batch.Text=(“00”+(i+1)).ToString();
NewCell3.控件.添加(批处理);
NewRow1.Cells.Add(NewCell3);
//status.Text=(“正在进行中”).ToString();
//NewCell4.控件.添加(状态);
NewCell4.Text=“进行中”;
NewCell4.ID=“状态”;
NewRow1.Cells.Add(NewCell4);
表1.行。添加(新增行1);
}
}
你在找这个吗
Table1.Rows[3].Cells[3].Text = "Hello World";
请记住,如果希望表在回发之间保持不变,则必须决定如何维护它的状态或每次重建它
[编辑]
下面是一个完整的示例,向您展示它的工作原理:
<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!";
}
受保护的无效页面加载(对象发送方、事件参数e)
{
对于(int-RowIndex=0;RowIndex<4;RowIndex++)
{
TableRow NewRow=新TableRow();
对于(int ColumnIndex=0;ColumnIndex<4;ColumnIndex++)
{
TableCell NewCell=新的TableCell();
NewCell.Text=“aaa”;
NewRow.Cells.Add(NewCell);
}
表1.行。添加(新行);
}
表1.行[3]。单元格[3]。Text=“Hello World!”;
}
您到底有什么问题?了解如何访问单个列?确定要访问哪个列?此更新是否在回发过程中?myTable.rows[0][“MyColumn”]=
。然后调用AcceptChanges
。完成。指定的参数超出有效值的范围。参数名称:indexI刚刚使用了threes作为示例。我不知道您的数据存储在什么索引中。我写了0,但它同样不起作用(在表中添加了10多行),我修改了我的答案。在您的例子中,如果要修改某个子控件,则需要进一步深入并修改它。