how will get session variable from gridview ....pls tell me the codings
How will get session from gridview
Collapse
X
-
-
Originally posted by radcaesarSession variable from gridview ? What you try to achieve ?
Can u explain your requirement in detail ?
:)
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
-
Originally posted by visalakshiyes
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
-
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
-
Comment
Comment