如何读取gridview某列中的利用a标签生成的超链接的显示文本?

来源:百度知道 编辑:UC知道 时间:2024/05/23 18:07:13
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="bound">
<Columns>
<asp:TemplateField HeaderText="test">
<ItemTemplate>
<a href='Default2.aspx'><%# Eval("UserName") %></a></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

我利用dataset绑定的gridview,然后在gridview中添加了一个模板列,利用a标签将datset中的“UserName”字段绑定该列,我现在想在gridview的RowDataBound事件中读取该超链接显示的文本应该怎么写啊?我尝试了下面的方法
protected void bound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
Label1.Text += e.Row.Cells[0].Text;
}

但是label上没有任何显示,单步调试时发现根本就没读取成功。麻烦大侠指点迷津啊

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView rowView = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label1.Text += rowView["UserName"].ToString();
}
}