0

我在 ASP.NET 页面中有 GRIDVIEW,我正在将其转换为基础网络数据网格。

现在我的网格具有打开文件、复制文件、编辑文件描述、通过电子邮件发送文件和删除文件的功能。

它基于文档。

现在假设如果我以删除文件为例,原始代码是:

  protected void lbEmailDocument_Click(object sender, CommandEventArgs e)

    {

        int index = Int32.Parse(e.CommandArgument.ToString());

        Session["strDocumentToAttach"] = ((Label)gvDocuments.Rows[index].Cells[0].FindControl("lblPath")).Text;

        Session["strSubject"] = "Case Document E-mail (Case # " + lblCaseNumber.Text.Trim() + ")";

        Session["strNote"] = "Please find the attached document " + ((Label)gvDocuments.Rows[index].Cells[0].FindControl("lblFileName")).Text;

        ScriptManager.RegisterStartupScript(Page, this.GetType(), "myPopUp", "<script language='Javascript'>mywin=window.open('Case_Email.aspx?CaseID=" + lblCaseID.Text + "', '', 'location=0,status=0,resizable=1,scrollbars=1,height=920px, width=1250px');mywin.moveTo(0,0);</script>", false);



        // Response.Redirect("Case_Email.aspx?CaseID=" + lblCaseID.Text);

    }

现在当我改变这个:而不是Rows[index].Cells[0]我无法访问单元格值。

请指导我,如何改变它。

实现你给出的代码我得到了以下错误:

在此处输入图像描述

4

1 回答 1

1

我相信您想使用Items而不是Cells.

此代码假定每个单元格都是模板化的。

  protected void lbEmailDocument_Click(object sender, CommandEventArgs e)

    {

        int index = Int32.Parse(e.CommandArgument.ToString());

        Session["strDocumentToAttach"] = ((Label)gvDocuments.Rows[index].Items[0].FindControl("lblPath")).Text;

        Session["strSubject"] = "Case Document E-mail (Case # " + lblCaseNumber.Text.Trim() + ")";

        Session["strNote"] = "Please find the attached document " + ((Label)gvDocuments.Rows[index].Items[0].FindControl("lblFileName")).Text;

        ScriptManager.RegisterStartupScript(Page, this.GetType(), "myPopUp", "<script language='Javascript'>mywin=window.open('Case_Email.aspx?CaseID=" + lblCaseID.Text + "', '', 'location=0,status=0,resizable=1,scrollbars=1,height=920px, width=1250px');mywin.moveTo(0,0);</script>", false);



        // Response.Redirect("Case_Email.aspx?CaseID=" + lblCaseID.Text);

    }

但是,如果您要查找的值在列中,那么您需要使用类似于以下的代码:

  protected void lbEmailDocument_Click(object sender, CommandEventArgs e)

    {

        int index = Int32.Parse(e.CommandArgument.ToString());

        Session["strDocumentToAttach"] = gvDocuments.Rows[index].Items.FindItemByKey("lblPath").Value;

        Session["strSubject"] = "Case Document E-mail (Case # " + lblCaseNumber.Text.Trim() + ")";

        Session["strNote"] = "Please find the attached document " + gvDocuments.Rows[index].Items.FindItemByKey("lblFileName").Value;

        ScriptManager.RegisterStartupScript(Page, this.GetType(), "myPopUp", "<script language='Javascript'>mywin=window.open('Case_Email.aspx?CaseID=" + lblCaseID.Text + "', '', 'location=0,status=0,resizable=1,scrollbars=1,height=920px, width=1250px');mywin.moveTo(0,0);</script>", false);



        // Response.Redirect("Case_Email.aspx?CaseID=" + lblCaseID.Text);

    }
于 2011-12-02T17:25:20.503 回答