locked
Storing Email ids for rows with a checkbox checked into a array and passing it using a session to a new page RRS feed

  • Question

  • User-555910934 posted

    I am new to .Net and I need help on a task

    I have a page with a gridview and each row has a checkbox.

    If a checkbox is checked, I need to pick up email id from that row and store it in an array and then pass the email ids for all rows were the checkbox is checked to a different page(by using sessions). And finally I need to input these email ids into a textbox on the other page. This other page looks like a Compose Email screen.

    Some rows might also a word document in them. If the user selects one such row, my code should pass this document onto the second page and add it as an attachment on that Compose Email page

    Any code help/guidance will be really appreaciated and points will be assigned. Please respond at the earliest. Thanks!

    Wednesday, January 2, 2013 11:01 PM

All replies

  • User-422529730 posted

    see below code

    aspx

    <asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" 
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            CellSpacing="2" style="margin-left: 58px; margin-top: 13px" DataKeyNames="email" >
              <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
              <Columns>
                  <asp:TemplateField>
                      <ItemTemplate>
                          <asp:CheckBox ID="CheckBox1" runat="server" />
                      </ItemTemplate>
                  </asp:TemplateField>
              </Columns>
    
        </asp:GridView>
        <asp:Button ID="get_email" runat="server" Text="Button"  runat="server" 
            onclick="Get_email_Click" />


    code behind

     protected void Get_email_Click(object sender, EventArgs e)
     {
    	string emailsid;
            foreach (GridViewRow row in gridView1.Rows)
            {
               if (((CheckBox)row.FindControl("CheckBox1")).Checked)
                {
    		if(emailsid == "" )
                    	emailsid = gridView1.DataKeys[row.RowIndex].Value.ToString(); // get the record's ID of this row
    		else 
    		  emailsid = emailsid  + "," + gridView1.DataKeys[row.RowIndex].Value.ToString(); // get the record's ID of this row
                   
                }
            }
    	session["emailIDs"] = emailsid ;
    	Response.Redirect("another page");
    
            
        }

    refer below URL

    http://www.codeproject.com/Articles/23833/DataKeyNames

    Thursday, January 3, 2013 12:13 AM
  • User-555910934 posted

    Thank you for your response!

    however as mentioned in the question, I also have a requirement, where

    "Some rows might also a word document in them. If the user selects one such row, my code should pass this document onto the second page and add it as an attachment on that Compose Email page (also adding the email id from that row into the To field)"

    How will I be able to accomplish this? Please let me know at the earliest! Thanks again for your quick response!

     

     

    Thursday, January 3, 2013 9:03 AM
  • User-555910934 posted

    Thank you for your response!

    however as mentioned in the question, I also have a requirement, where

    "Some rows might also a word document in them. If the user selects one such row, my code should pass this document onto the second page and add it as an attachment on that Compose Email page (also adding the email id from that row into the To field)"

    How will I be able to accomplish this? Please let me know at the earliest! Thanks again for your quick response!

    Thursday, January 3, 2013 9:04 AM