Asp.net 如何将数据表行值更新为超链接?

Asp.net 如何将数据表行值更新为超链接?,asp.net,Asp.net,我在c#代码的dt中有一个数据表,它有[0]列,数据类型为int。因此,当我达到表中的第7个值时,我需要转换为hyperlink并将其添加回数据表 int x = int.Parse(dt.Rows[7][0].ToString()); dt.Row[7][0] = "<a href=\"http:www.google.com\">" + x + "</a>"; intx=int.Parse(dt.Rows[7][0].ToString()); dt.行[7][0]=“

我在c#代码的dt中有一个数据表,它有[0]列,数据类型为int。因此,当我达到表中的第7个值时,我需要转换为hyperlink并将其添加回数据表

int x = int.Parse(dt.Rows[7][0].ToString());
dt.Row[7][0] = "<a href=\"http:www.google.com\">" + x + "</a>";
intx=int.Parse(dt.Rows[7][0].ToString());
dt.行[7][0]=“”;

但是它给了我一个不能接受字符串值为整数的错误。如何解决这个问题?

您如何创建数据表?该列可能已被键入int,因此无法接受字符串值

更好的方法可能是更改数据绑定控件以显示链接

protected override void OnInit(EventArgs e) {
    base.OnInit(e);
    DataBound += new EventHandler(GridView1_DataBound);
}

void GridView_RowDataBound(object sender, GridViewRowEventArgs e) {
    GridView gridview = (GridView)sender;
    if (e.Row.RowType == DataControlRowType.DataRow) {
        for (int i = 0; i < gridview.Columns.Count; i++) {
            DataControlField obj1 = gridview.Columns[i];
            if (obj1.GetType() == typeof(BoundField)) {
                BoundField field = (BoundField)obj1;
                string datafield = field.DataField;
                object value = DataBinder.Eval(e.Row.DataItem, datafield);
                Literal c = new Literal();
                c.Text = "";
                e.Row.Cells[i].Controls.Add(c);
            }
        }
    }
}
protected override void OnInit(事件参数e){
碱基.奥尼特(e);
DataBound+=新事件处理程序(GridView1_DataBound);
}
void GridView_RowDataBound(对象发送方,GridViewRowEventArgs e){
GridView GridView=(GridView)发送方;
如果(e.Row.RowType==DataControlRowType.DataRow){
for(int i=0;i
纠正我,我错了。添加字符串类型的额外列

dt.Columns.Add("LinkColumn");
...
dt.Rows[7]["LinkColumn"]=string.Format("<a href='#'>{0}</a>",x);
dt.Columns.Add(“LinkColumn”);
...
dt.Rows[7][“LinkColumn”]=string.Format(“,x”);

无法将字符串值分配给int-type列。我很确定您需要将x更改为x.ToString()。更好的是,String.Format(“,x);。