2011-12-02 132 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:更新答案以顯示獲取值的兩種方式,具體取決於單元格是否實際模板化。 –

相關問題