Click here to Skip to main content
16,021,430 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello! I'm making a mailing system program and I'm currently working on the inbox page. I want the list of recieved mail be viewed in a gridview and the subject column be clickable so that it can redirect to the body of the message. And I made that work with these code.

XML
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
          e.Row.Cells[2].Text = "<a href='message.aspx?param1="+e.Row.Cells[0].Text+"&param2=1'>" + e.Row.Cells[2].Text + "</a>";
            }


Now, I'm trying to add a checkbox in the gridview where the user can select multiple mails to delete. I've already done this program in other webform(but without clickable column). Code is like this.

protected void Button1_Click(object sender, EventArgs e)
        {
            StringCollection idCollection = new StringCollection();


            foreach (GridViewRow row in GridView1.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkDelete = (CheckBox)row.Cells[0].FindControl("myCheckBox");

                    if (chkDelete != null)
                    {
                        if (chkDelete.Checked)
                        {
                            string strid = row.Cells[1].Text;
                            idCollection.Add(strid);

                        }
                    }
                }
            }

            MoveTo(idCollection);
            BindData(); 
        }

        private void MoveTo(StringCollection idCollection)
        {
            MySqlConnection connection = new MySqlConnection(connectionString);
            
            MySqlCommand cmd = new MySqlCommand();
            string IDs = "";
            Label3.Text = IDs;
            foreach (string id in idCollection)
            {
                IDs += id.ToString() + ",";
                Label3.Text = IDs;


                string strIDs =
               IDs.Substring(0, IDs.LastIndexOf(","));
                string strSql = "DELETE FROM recievemail WHERE recievemailID in (" + strIDs + ")";
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strSql;
                cmd.Connection = connection;
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
                BindData();
            }
        }


And that works fine in that webform. But then, when I try to combine the two in the inbox page. I kept on receiving this error...


Quote:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
<pre lang="xml">Line 112: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
Line 113: {
Line 114: e.Row.Cells[1].Text = &quot;&lt;a href=&#39;message.aspx&#39;&gt;&quot; + e.Row.Cells[1].Text + &quot;&lt;/a&gt;&quot;;
Line 115: }
Line 116: }



Any idea on how to solve the problem? Thanks.
Posted
Comments
jmpapa 21-Feb-13 2:35am    
Sorry. I just found the real problem. It's not really the checkbox and the hyperlink that conflicts. It is the paging and hyperlink. How to solve this? any idea? Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900