473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How will get session from gridview

how will get session variable from gridview ....pls tell me the codings
Jul 6 '07 #1
5 4052
radcaesar
759 Expert 512MB
Session variable from gridview ? What you try to achieve ?

Can u explain your requirement in detail ?

:)
Jul 6 '07 #2
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.....this concept.....

i am doing....selected 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_SelectedIndexChanged(object sender, EventArgs e)
{

Session["CompanyName"] =GridView1.SelectedRow.Cells[1].Text;
Response.Redirect("Default6.aspx");

}

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

string str =ConfigurationSettings.AppSettings.Get("connection ");
protected void Page_Load(object sender, EventArgs e)
{
if (TextBox2.Text == "")
{
con = new SqlConnection(str);
cmd = new SqlCommand("SELECT [Company Id], [CompanyName], [Address1], [ContactPerson], [EmailId], [Website] FROM [seller] ", con);
con.Open();
dr = cmd.ExecuteReader();
Response.Write(Session["CompanyName"]);
while (dr.Read())
{
if (Convert.ToString(Session["CompanyName"]) == dr["CompanyName"].ToString())
{
TextBox1.Text = dr["Company Id"].ToString();
TextBox2.Text = dr["CompanyName"].ToString();
TextBox3.Text = dr["Address1"].ToString();
TextBox4.Text = dr["EmailId"].ToString();
TextBox5.Text = dr["Website"].ToString();
TextBox6.Text = dr["ContactPerson"].ToString();
;
}
}

}

}
}
Jul 6 '07 #3
dip_developer
648 Expert 512MB
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.....this concept.....

i am doing....selected 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_SelectedIndexChanged(object sender, EventArgs e)
{

Session["CompanyName"] =GridView1.SelectedRow.Cells[1].Text;
Response.Redirect("Default6.aspx");

}

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

string str =ConfigurationSettings.AppSettings.Get("connection ");
protected void Page_Load(object sender, EventArgs e)
{
if (TextBox2.Text == "")
{
con = new SqlConnection(str);
cmd = new SqlCommand("SELECT [Company Id], [CompanyName], [Address1], [ContactPerson], [EmailId], [Website] FROM [seller] ", con);
con.Open();
dr = cmd.ExecuteReader();
Response.Write(Session["CompanyName"]);
while (dr.Read())
{
if (Convert.ToString(Session["CompanyName"]) == dr["CompanyName"].ToString())
{
TextBox1.Text = dr["Company Id"].ToString();
TextBox2.Text = dr["CompanyName"].ToString();
TextBox3.Text = dr["Address1"].ToString();
TextBox4.Text = dr["EmailId"].ToString();
TextBox5.Text = dr["Website"].ToString();
TextBox6.Text = dr["ContactPerson"].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 & "'
Jul 6 '07 #4
radcaesar
759 Expert 512MB
Declare the field like this,

<asp:HyperLinkField DataTextField="CategoryName" DataNavigateUrlFields="CategoryID" DataNavigateUrlFormatString="NewPage.aspx?id={0}"
HeaderText="CategoryName" />

In the destination page query it like this,

if (Request.QueryString["id"] != null)
{
int yourValue = Convert.ToInt32(Request.QueryString["id"]);
}
Jul 6 '07 #5
hi... how to declare the querystring if i am using an image button in the gridview.. thanks
Oct 22 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: shank | last post by:
Will Session() (created in SSL) hold its value in SSL, when you go from https://abc to https://xyz and back to https://abc ? Mine does not appear to retain its value. thanks
1
by: ABC | last post by:
Will Session automatic clear memory when I unload web page?
6
by: Joseph I. Ceasar | last post by:
I have an ASP .Net 2.0 site that I am working on. It has a master page and a content page. I also created a separate class module that returns a DataSet to feed my GridView. So far, so good. ...
12
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values...
1
by: ist | last post by:
Hi, I am trying to create a Session-Wide, Disconnected, Updatable DataTable (or DataSet) object and use it through an ASP.NET GridView. The scenario is this: 1. When the page is first loaded,...
0
by: Jeff | last post by:
ASP.NET 2.0 My webpage has a GridView showing rows from a table in the database. All these rows are stored in the session object -what's actually stored is generic list of objects, as this:...
2
by: Blasting Cap | last post by:
I've got a gridview (that I converted over from a datagrid, which had been working properly), that is doubling up the number of rows returned. When it was running as a datagrid, the same code sent...
2
by: psion | last post by:
Hi, We have a gridview on a webpage, which we would like to be 100% of the table cell in which it is placed. When we specify the width to be 100%, this has no effect, but only if we specify a...
0
by: jaredciagar | last post by:
Hi Guys, can You help me please in my project.... I'm using VB Script,ASP.Net,MS SQL Server 2005 I want to save data in gridview control from data in textbox control.... How can I Do It?...
1
by: markus007 | last post by:
If you are missing percentage formats or date formats make sure that the .NET Runtime Optimization Service v2.0.50727_X86 is running on your server. This when turned off, will affect gridview...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.