2011-12-02 26 views
0

我在ASP.NET Page中有GRIDVIEW,并将其转换为infragistics webdata网格。如何在DropDownList_SelectedIndexChanged事件中获取WebDataGrid单元格值?

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

它基于文档。

现在假设,如果我采取例如删除文件中的原始代码是:

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

我相信你想使用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); 

    } 
+0

能否请您帮忙修改使用的项目上面的代码? – Bebu

+0

@Bebu:更新答案以显示获取值的两种方式,具体取决于单元格是否实际模板化。 –

相关问题