【发布时间】:2011-06-16 06:12:39
【问题描述】:
我想用HyperLink 和其他两个字段填充GridView。
我半心半意地尝试了以下方法。它给出了错误。
SqlCommand comm = new SqlCommand(
@"Select
FileUpload.FileName AS FileName,
FileUpload.FilePath AS PATH,
SubjectMaster.SubjectName AS Subject,
MemberPersonalInformation.FirstName As SharedBy
from FileUpload
INNER JOIN ContentManagement
ON ContentManagement.FileId=FileUpload.FileId
INNER JOIN MemberPersonalInformation
ON MemberPersonalInformation.MemberId=ContentManagement.CreatedBy
INNER JOIN SubjectMaster
ON ContentManagement.SubjectName=SubjectMaster.SubjectId
where
FileUpload.FileId in
(
Select FileId
from ContentManagement
where
ContentId in
(
Select ContentId
from ContentToIndividual
where ShowToMemberId=@MemberId
) and
ContentManagement.ContentTypeId=@TPD and
ContentManagement.SessionId=@SessionId
)", conn);
conn.Open();
SqlDataReader rdr = comm.ExecuteReader();
int i = 0;
while (rdr.Read())
{
string fip = rdr["PATH"].ToString();
GridViewRow di = GridView1.Rows[i];
HyperLink h1 = (HyperLink)di.FindControl("Hyperlink1");
h1.Text = rdr["FileName"].ToString();
h1.NavigateUrl = "download.aspx?filepath=" + fip;
di.Cells[1].Text = rdr["SharedBy"].ToString();
di.Cells[2].Text = rdr["Subject"].ToString();
i++;
}
rdr.Close();
收到错误消息
索引超出范围。一定是 非负且小于 集合。
参数 名称:索引
如果有人建议我更好的方法来执行此操作或更正此错误。
【问题讨论】:
-
您是否有意尝试使用
1和2,而不是.Cells[0]和.Cells[1]? -
抱歉,我想我正在打印
Cells[0]中的超链接。 -
@ILLUMINATI7590:您能否指定出现错误的行..
-
GridViewRow di = GridView1.Rows[i];我这里出错了。 -
@ILLUMINATI7590:我认为这里异常的原因是返回的结果集 - 由读者读取 - 具有比
GridView.Rows集合更多的项目。
标签: c# asp.net gridview templatefield