How will get session from gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • visalakshi
    New Member
    • Jul 2007
    • 3

    How will get session from gridview

    how will get session variable from gridview ....pls tell me the codings
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    #2
    Session variable from gridview ? What you try to achieve ?

    Can u explain your requirement in detail ?

    :)

    Comment

    • visalakshi
      New Member
      • Jul 2007
      • 3

      #3
      Originally posted by radcaesar
      Session variable from gridview ? What you try to achieve ?

      Can u explain your requirement in detail ?

      :)
      yes

      I have two forms ...one form-gridview ...another oneform have some textbox

      in gridview i have three columns....one column is company Name with hyperlink .....if i click one company name it will show that related company details in another form to textbox.....thi s concept.....

      i am doing....select ed row put into session ......that session variable compare to another form textbox.....but it not working ....wat can i do...


      this is my coding

      ingridview
      --------------

      protected void GridView1_Selec tedIndexChanged (object sender, EventArgs e)
      {

      Session["CompanyNam e"] =GridView1.Sele ctedRow.Cells[1].Text;
      Response.Redire ct("Default6.as px");

      }

      In nextform
      ------------------

      string str =ConfigurationS ettings.AppSett ings.Get("conne ction");
      protected void Page_Load(objec t sender, EventArgs e)
      {
      if (TextBox2.Text == "")
      {
      con = new SqlConnection(s tr);
      cmd = new SqlCommand("SEL ECT [Company Id], [CompanyName], [Address1], [ContactPerson], [EmailId], [Website] FROM [seller] ", con);
      con.Open();
      dr = cmd.ExecuteRead er();
      Response.Write( Session["CompanyNam e"]);
      while (dr.Read())
      {
      if (Convert.ToStri ng(Session["CompanyNam e"]) == dr["CompanyNam e"].ToString())
      {
      TextBox1.Text = dr["Company Id"].ToString();
      TextBox2.Text = dr["CompanyNam e"].ToString();
      TextBox3.Text = dr["Address1"].ToString();
      TextBox4.Text = dr["EmailId"].ToString();
      TextBox5.Text = dr["Website"].ToString();
      TextBox6.Text = dr["ContactPer son"].ToString();
      ;
      }
      }

      }

      }
      }

      Comment

      • dip_developer
        Recognized Expert Contributor
        • Aug 2006
        • 648

        #4
        Originally posted by visalakshi
        yes

        I have two forms ...one form-gridview ...another oneform have some textbox

        in gridview i have three columns....one column is company Name with hyperlink .....if i click one company name it will show that related company details in another form to textbox.....thi s concept.....

        i am doing....select ed row put into session ......that session variable compare to another form textbox.....but it not working ....wat can i do...


        this is my coding

        ingridview
        --------------

        protected void GridView1_Selec tedIndexChanged (object sender, EventArgs e)
        {

        Session["CompanyNam e"] =GridView1.Sele ctedRow.Cells[1].Text;
        Response.Redire ct("Default6.as px");

        }

        In nextform
        ------------------

        string str =ConfigurationS ettings.AppSett ings.Get("conne ction");
        protected void Page_Load(objec t sender, EventArgs e)
        {
        if (TextBox2.Text == "")
        {
        con = new SqlConnection(s tr);
        cmd = new SqlCommand("SEL ECT [Company Id], [CompanyName], [Address1], [ContactPerson], [EmailId], [Website] FROM [seller] ", con);
        con.Open();
        dr = cmd.ExecuteRead er();
        Response.Write( Session["CompanyNam e"]);
        while (dr.Read())
        {
        if (Convert.ToStri ng(Session["CompanyNam e"]) == dr["CompanyNam e"].ToString())
        {
        TextBox1.Text = dr["Company Id"].ToString();
        TextBox2.Text = dr["CompanyNam e"].ToString();
        TextBox3.Text = dr["Address1"].ToString();
        TextBox4.Text = dr["EmailId"].ToString();
        TextBox5.Text = dr["Website"].ToString();
        TextBox6.Text = dr["ContactPer son"].ToString();
        ;
        }
        }

        }

        }
        }

        i dont understand your logic......
        In my opinion do the following...
        1.when clicking on company name link hold the ID of that company(if you are using an company_id.If not then you should use.Querying with company name is not a good idea) in a variable.

        2.Pass that variable as a Query string when you are redirecting your page to another one.

        3.In the Page_Load event of that second page retrive the company_id from the query string variable in a local variable(say comp_id )

        4.Now execute a SQL query like

        SELECT Company Id, CompanyName, Address1, ContactPerson, EmailId, Website FROM seller WHERE Company Id='" & comp_id & "'

        Comment

        • radcaesar
          Recognized Expert Contributor
          • Sep 2006
          • 759

          #5
          Declare the field like this,

          <asp:HyperLinkF ield DataTextField=" CategoryName" DataNavigateUrl Fields="Categor yID" DataNavigateUrl FormatString="N ewPage.aspx?id= {0}"
          HeaderText="Cat egoryName" />

          In the destination page query it like this,

          if (Request.QueryS tring["id"] != null)
          {
          int yourValue = Convert.ToInt32 (Request.QueryS tring["id"]);
          }

          Comment

          • qqqqqqqqqq
            New Member
            • Oct 2008
            • 2

            #6
            hi... how to declare the querystring if i am using an image button in the gridview.. thanks

            Comment

            Working...