i have data table with dropdownlist filter by language after i change the language to another then change the status of any record the page postback with the defult value of dropdownlist
i want to do some thing like catch dropdownlist.selectedvalue in session and return it at page postback
i try this code
if (action == "state" && id != "")
{
Session["drplst_lng"] = drplst_lng.SelectedValue.ToString();
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["IPConnectionString"].ConnectionString);
SqlCommand cmdz = new SqlCommand("UPDATE [product_static_data] SET [product_status]=~[product_status] WHERE product_id='" + id + "'", cn);
cmdz.Connection = cn;
cmdz.CommandType = CommandType.Text;
cn.Open();
cmdz.ExecuteScalar();
cn.Close();
drplst_lng.SelectedValue = Session["drplst_lng"].ToString();
}
Not sure why to use the Session. I beilive if you set the Autopostback attribute to the control = true then the selected value appears automatically. You do not need to use session. That is what I understood from your code. You need to pull back the selected
value of the dropdown all the time.
Load the Dropdown only for the first time and rest all post back events do not require to load.
UPDATE [product_static_data] SET [product_status]=~[product_status
Here's a question:SET [product_status]=~[product_status
You cannot say that, because that's a column instead of value, so you should say something like this:
SET [product_status]= your real value
And then
eng.muslim
cmdz.ExecuteScalar();
If you wanna do update to your column value, please just use ExecuteNonQuery()instead.
eng.muslim
UPDATE [product_static_data] SET [product_status]=~[product_status
Your SQL statement will raise the problem of parameterized problem and cause the SQL injection. Please use SQL Parameter instead of single string's combination.
eng.muslim
0 Points
10 Posts
how to catch dropdownlist.selectedvalue in session
Dec 13, 2012 10:29 AM|LINK
hello
i have data table with dropdownlist filter by language after i change the language to another then change the status of any record the page postback with the defult value of dropdownlist
i want to do some thing like catch dropdownlist.selectedvalue in session and return it at page postback
i try this code
if (action == "state" && id != "") { Session["drplst_lng"] = drplst_lng.SelectedValue.ToString(); SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["IPConnectionString"].ConnectionString); SqlCommand cmdz = new SqlCommand("UPDATE [product_static_data] SET [product_status]=~[product_status] WHERE product_id='" + id + "'", cn); cmdz.Connection = cn; cmdz.CommandType = CommandType.Text; cn.Open(); cmdz.ExecuteScalar(); cn.Close(); drplst_lng.SelectedValue = Session["drplst_lng"].ToString(); }chaaraan
Contributor
2170 Points
484 Posts
Re: how to catch dropdownlist.selectedvalue in session
Dec 13, 2012 10:57 AM|LINK
Hi
Did you bind the ddlb in Not Postback in Page load
if(!IsPostBack)
{
BindDDL();
}
Regards,
Charan
eng.muslim
0 Points
10 Posts
Re: how to catch dropdownlist.selectedvalue in session
Dec 13, 2012 11:10 AM|LINK
no
this is my dropdownlist design
<div style="float: left; margin-top: 7px;"> <label> Product Language : </label></div> <div style="float: left;"> <asp:dropdownlist class="chzn-single chzn-single-with-drop" runat="server" id="drplst_lng" datasourceid="content_language" datatextfield="lang_name" datavaluefield="lang_id" autopostback="True" onselectedindexchanged="content_lang_SelectedIndexChanged1" height="18px" width="402px" enableviewstate="true"></asp:dropdownlist> <asp:sqldatasource id="content_language" runat="server" connectionstring="<%$ ConnectionStrings:IPConnectionString %>" selectcommand=" select language_name as [lang_name],language_id as [lang_id] from language where language_status = 1 "></asp:sqldatasource> </div> </div>when i select english the page postback and load the data table with the items that has the english id
then when i chage the status of any item in the data table the page postback and the drop down list back to the default language arabic
i want to back to english i hope you understand me
sorry for bad english
this is my html code
<span class="tip"><a href="product.aspx?action=state&id={$id}" title="Change Product Status"> <img src="../images/icon/color_18/lock.png" width="16" height="16"></a></span>nadellas
Participant
1218 Points
299 Posts
Re: how to catch dropdownlist.selectedvalue in session
Dec 13, 2012 12:06 PM|LINK
Not sure why to use the Session. I beilive if you set the Autopostback attribute to the control = true then the selected value appears automatically. You do not need to use session. That is what I understood from your code. You need to pull back the selected value of the dropdown all the time.
Load the Dropdown only for the first time and rest all post back events do not require to load.
Let me know if that is incorrect.
tanks
-Srini
eng.muslim
0 Points
10 Posts
Re: how to catch dropdownlist.selectedvalue in session
Dec 13, 2012 12:35 PM|LINK
so how can i pull the dropdownlist.selected value after postback
sarathi125
Star
13599 Points
2691 Posts
Re: how to catch dropdownlist.selectedvalue in session
Dec 13, 2012 01:26 PM|LINK
Hi,
your DropDownList will keep its state between postbacks without any need of such coding...
Maybe you are re-binding your dropdownlist on each postback? This may couse the selectedindex to be reset...
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: how to catch dropdownlist.selectedvalue in session
Dec 14, 2012 01:17 AM|LINK
Here's a question:SET [product_status]=~[product_status
You cannot say that, because that's a column instead of value, so you should say something like this:
And then
If you wanna do update to your column value, please just use ExecuteNonQuery() instead.
Your SQL statement will raise the problem of parameterized problem and cause the SQL injection. Please use SQL Parameter instead of single string's combination.