我有 gridview ,我可以访问单元格的值但不能访问超链接。 当我尝试获取它时,我只得到空字符串。第 5 个单元格是超链接单元格。
protected void GridView4_RowDeleting(object sender, GridViewDeleteEventArgs e)
TableCell cell = GridView4.Rows[e.RowIndex].Cells[1];
string sid = cell.Text;
string id = Session["id"].ToString();
TableCell cell2 = GridView4.Rows[e.RowIndex].Cells[2];
string sid2 = cell2.Text;
TableCell cell3 = GridView4.Rows[e.RowIndex].Cells[5];
string sid3 = cell3.Text;
这是我的超链接:
<asp:HyperLinkField DataNavigateUrlFields="DosyaAdresi" DataNavigateUrlFormatString="dosyalar\{0}" DataTextField="DosyaAdresi" HeaderText="DosyaAdresi" DataTextFormatString="DosyaAdresi" Text="DosyaAdresi" >
我希望 sid3 像“1531351.jpg”但返回“”。
最佳答案
您的表格单元格没有任何文本,而是有一个 HyperLink 控件,您应该检索它然后获取它的文本。
string sid3 = ((HyperLink)GridView4.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
关于c# - 我怎样才能在 gridview 中获取超链接的值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55971251/