如何将gridview的超链接字段的navigationUrl设置为类的属性? [英] how can i set navigateUrl of a hyperlinkfield of gridview to a class's propperty?
本文介绍了如何将gridview的超链接字段的navigationUrl设置为类的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类,当我定义它的对象时,我必须为其上载一个描述文件,并且描述路径另存为类中的一个属性.所以我想当此类对象加载到gridview中时,有一个列作为超链接,当我单击列中的文本时,它会下载该行的描述文件.
请帮助我
谢谢.
i have a class that when i define an object of it i have to upload a description file for it and the path of description save as a property in class. so i want when the objects of this class load in gridview i have a column as a hyperlink that when i click the text in column it download the description file for that row.
please help me
thank you.
推荐答案
您必须在gridview.rowdatabound
事件中执行此操作,请参阅:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx [
You have to do that ingridview.rowdatabound
event, refer this:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx[^]
我以这种方式更改了代码,当我的页面中有一个DropDownList时,我从中选择一个项目,将加载GridHomework的数据.
I changed my code in this way, i have a DropDownList in my page when i select an item from it, the GridHomework''s data is loaded.
protected void dpdGroup_SelectedIndexChanged(object sender, EventArgs e)
{
int GroupId =Convert.ToInt32( dpdGroup.SelectedItem.Value);
CourseGroup group = DB.CourseGroups.Where(g => g.Id == GroupId).First();
IEnumerable<homework> lstHomework = group.GetHomework();
GridHomework.DataSource = lstHomework;
GridHomework.DataBind();
foreach (GridViewRow gvRow in GridHomework.Rows)
{
int HwId = (int)GridHomework.DataKeys[gvRow.RowIndex].Value;
Homework Hw = DB.Homeworks.Where(h => h.Id == HwId).FirstOrDefault();
HyperLink link = new HyperLink();
link =(HyperLink)gvRow.FindControl("HyperLink1");
link.NavigateUrl = "http://" + Request.Url.Authority + "/HomeWorkManagementSystem/Upload/" + Hw.DscripPath;
}
}
</homework>
这篇关于如何将gridview的超链接字段的navigationUrl设置为类的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文