如何在DropDownList_SelectedIndexChanged事件中获取WebDataGrid单元格值?

时间:2011-12-02 17:08:47

标签: c# asp.net gridview infragistics webdatagrid

我在ASP.NET页面中有GRIDVIEW,我正在将其转换为infragistics webdata网格。

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

它基于文件。

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

  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]我无法访问单元格值。

请指导我,如何更改。

实现您提供的代码我遇到以下错误:

enter image description here

1 个答案:

答案 0 :(得分: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);

    }