Reputation: 65
I have GRIDVIEW in ASP.NET Page and I am converting it into infragistics webdata grid.
Now my grid has functionalities of opening file, copy file, edit description of file, emailing file and deleting file.
It is based on documents.
Now suppose if I take example of deleting file the original code is:
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);
}
Now when I change this : Instead of Rows[index].Cells[0]
I am not able to access the cell value.
Please guide me through, How to change it.
Implementing the code given by you I got following error:
Upvotes: 0
Views: 5897
Reputation: 44931
I believe that you want to use Items
instead of Cells
.
This code assumes that each cell is templated.
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);
}
However, if the values you are looking for are in columns, then you need to use code similar to the following:
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);
}
Upvotes: 1