Click here to Skip to main content
15,896,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

here is my code where i want to pass the IMAGE_ID of selected rows onto next page..plz help
C#
public partial class ADMIN_SELECT_IMAGE : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            BindGridView();
    }

    private void BindGridView()
    {
        ConnectionStringSettings set = ConfigurationManager.ConnectionStrings["WATERMARKING"];
        String cns = set.ConnectionString;
        SqlConnection con = new SqlConnection(cns);
        con.Open();
        string sql = "Select IMAGE_ID,IMAGE_TYPE,IMAGE_SIZE,IMAGE_CONTENT from IMAGE";
        SqlDataAdapter da = new SqlDataAdapter(sql, cns);
        DataTable dt = new DataTable();
        da.Fill(dt);
        gvCheckboxes.DataSource = dt;

        gvCheckboxes.DataBind();

        con.Close();
    }
   
    protected void gvCheckboxes_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
   
    private void SelectRecords(StringCollection sc)
    {
        //int id =(int)this.gvCheckboxes.SelectedDataKey.Value;
        ConnectionStringSettings set = ConfigurationManager.ConnectionStrings["WATERMARKING"];
        String cns = set.ConnectionString;
        SqlConnection con = new SqlConnection(cns);
        con.Open();

        StringBuilder sb = new StringBuilder(string.Empty);
       
        foreach (string item in sc)
        {
            const string sqlStatement = "SELECT IMAGE_ID,IMAGE_CONTENT FROM IMAGE WHERE IMAGE_ID";
           
            sb.AppendFormat("{0}='{1}'; ", sqlStatement, item);
           
        }

        try
        {
            SqlCommand cmd = new SqlCommand(sb.ToString(), con);
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

             reader.Read();
             if (reader.HasRows)
            {
                Response.Redirect("ADMIN_SELECT_LOGO.aspx");
             
            }
            else
            {
                //Response.Write("image deleted successfully");
                Response.Write("error in selection");
            }
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            con.Close();
        }
    }

    protected void ButtonSelect_Click(object sender, EventArgs e)
    {
        StringCollection sc = new StringCollection();
        string id = string.Empty;

        for (int i = 0; i < gvCheckboxes.Rows.Count; i++)
        {
            CheckBox cb = (CheckBox)gvCheckboxes.Rows[i].Cells[0].FindControl("CheckBox1");

            if (cb != null)
            {
                if (cb.Checked)
                {
                    id = gvCheckboxes.Rows[i].Cells[1].Text;
                    sc.Add(id);
                }
            }
        }

        SelectRecords(sc);
        BindGridView();
    }

    protected void gvCheckBoxes_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Button b = (Button)e.Row.FindControl("ButtonSelect");
            b.Attributes.Add("onclick", "return ConfirmOnSelect();");
        }
    }

    protected void LinkButton7_Click1(object sender, EventArgs e)
    {
        Response.Redirect("ADMIN_HOME.aspx");
    }
    protected void LinkButton6_Click1(object sender, EventArgs e)
    {
        Response.Redirect("LOGIN.aspx");
    }
}
Posted
Updated 5-Feb-11 7:05am
v2

well, you say you are trying to pass thru sessions, but the code does not reflect this.
this example[^] shows how to use sessions with a good bunch of information:
(an example code from the link)
//Storing UserName in Session
Session["UserName"] = txtUser.Text;

//Check weather session variable null or not
        if (Session["UserName"] != null)
        {
            //Retrieving UserName from Session
            lblWelcome.Text = "Welcome : " + Session["UserName"];
        }
        else
        {
         //Do Something else
        }


in addition, objects can be stored in sessions:
//Storing dataset on Session
        Session["DataSet"] = _objDataSet;  
//and following code shows how we can retrieve that dataset from the session 
//Check weather session variable null or not
        if (Session["DataSet"] != null)
        {
            //Retrieving UserName from Session
            DataSet _MyDs = (DataSet)Session["DataSet"];
        }
        else
        {
            //Do Something else
        }


instead, you can use query strings as in here[^]
 
Share this answer
 
v2
Comments
RKT S 6-Feb-11 4:28am    
hi, i have tried this also bt still its passing id as 0 only...dont knw wats the problem
MCY 6-Feb-11 7:18am    
is it possible that your id is zero? have you checked its value before passing to a session?
RKT S 8-Feb-11 6:14am    
i am trying to pass the value thru query string and no the id values start from 1..its not zero...
MCY 8-Feb-11 8:33am    
So you see that id is not zero in the address bar, right?
it will be easier to solve the problem if you post the code where you get the id plus how do you form your querystring plus how do you get id from querystring.
With either a session variable or a querystring parameter.
 
Share this answer
 
Comments
RKT S 5-Feb-11 13:38pm    
hi john,am trying to pass it thru sessions...bt it is always passing id value as 0 only...

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