|
I created a form view in asp.net for a data entry web page. User inputs data which is supposed to get inserted into my MySql database in a existing database. but when I try the following code, I get the following error:
System.Data.Odbc.OdbcException: ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'product_id, 'Button Up'product_name, 'shirts'product_desc, 1000tot_qty, 36tot_ca' at line 2
This is the script I am running in my .aspx file.
InsertCommand="insert into product(product_id, product_name, product_desc, tot_qty, tot_cartons, cost, tot_colors,qty_per_carton, arrival_date, custom_clearedby, ship_mode)
values( ?product_id, ?product_name, ?product_desc, ?tot_qty, ?tot_cartons, ?cost, ?tot_colors,?qty_per_carton, ?arrival_date, ?custom_clearedby, ?ship_mode);
I would really appreciate any help/insight.
Thanks in advance
modified on Monday, May 19, 2008 12:17 PM
|
|
|
|
|
When trouble shooting commands like this, it always helps to show all of the relevant code (e.g. paramaters).
Each paramater "?some_param" should be assigned a value, you did not post this part of the code. Also, the paramaters should be added in the same order they are used in you MySql statement. I also don't see you closing the string, however this might be a copy/paste typo. Nonetheless, complete code is essential especially when this appears to be some type of string problem.
Based on your posted example, they should look like this:
mysqlCmd.Parameters.AddWithValue("?product_id", "some_value")
mysqlCmd.Parameters.AddWithValue("?product_name", "some_value")
mysqlCmd.Parameters.AddWithValue("?product_desc", "some_value")
etc..
Hope this helps!
|
|
|
|
|
I want to Format a value in report..Iam using component designer as report tool..
xmlDoc.Load(strPath & "/Reports/Analysis Reports/ReservedItemsSummary.xml")
xmlDoc.GetElementsByTagName("pssl_unitprice").Item(0).InnerXml.Format = "#,##0.000"
this syntax is wrong..
can any one help how to format the value of field(pssl_unitprice) from xml file...
I want to format the value 0.000 format
|
|
|
|
|
Hi,
I made a class file , which is being used to interact with the database.
Can i get ur views to improve it.
I m doing all the rollback /commit transaction at the stored procedure level.
According to me this is my Best code ever written in my carrier.
Here is the code.....
using System;<br />
using System.Data;<br />
using System.Configuration;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Web.UI.HtmlControls;<br />
using System.Data.SqlClient;<br />
<br />
namespace MyClasses<br />
{<br />
public class AddParameters<br />
{ <br />
public AddParameters[] p;<br />
internal SqlParameter param = new SqlParameter();<br />
public AddParameters()<br />
{<br />
p = new AddParameters[1];<br />
}<br />
public void ParameterFunction<T>(string ParameterName, T _ParameterValue, ParameterDirection ParameterDirection, SqlDbType ParameterType)<br />
{<br />
if (p[p.Length - 1] != null)<br />
{<br />
AddParameters[] temp = new AddParameters[p.Length];<br />
p.CopyTo(temp, 0);<br />
p = new AddParameters[p.Length + 1];<br />
for (int i = 0; i < p.Length - 1; i++)<br />
{<br />
p[i] = temp[i];<br />
}<br />
p[p.Length - 1] = new AddParameters();<br />
p[p.Length - 1].param.ParameterName = ParameterName;<br />
p[p.Length - 1].param.Value = _ParameterValue;<br />
p[p.Length - 1].param.Direction = ParameterDirection;<br />
p[p.Length - 1].param.SqlDbType = ParameterType;<br />
}<br />
else<br />
{<br />
p[0] = new AddParameters();<br />
p[0].param.ParameterName = ParameterName;<br />
p[0].param.SqlValue = _ParameterValue;<br />
p[0].param.Direction = ParameterDirection;<br />
p[0].param.SqlDbType = ParameterType;<br />
}<br />
}<br />
}<br />
<br />
public class DatabaseInteraction
{<br />
AddParameters ad = null;<br />
SqlConnection con = null;<br />
private string connectionstring = "";<br />
private string StoredProcedure = "";<br />
SqlCommand cmd = null;<br />
DataSet ds = null;<br />
SqlDataAdapter sqlad = null;<br />
public void AddParameters<T>(string Parametername, T Parametervalue, ParameterDirection ParameterDirection, SqlDbType type)<br />
{<br />
}<br />
public DatabaseInteraction()<br />
{<br />
<br />
}<br />
public static string ChangeDateFormat(string t)<br />
{<br />
string dat = "";<br />
DateTime datformat;<br />
if (DateTime.TryParse(t, out datformat))<br />
{<br />
dat = datformat.ToString("dd/MM/yyyy");<br />
return dat;<br />
}<br />
return dat;<br />
}<br />
public DatabaseInteraction(string constr)<br />
{<br />
connectionstring = constr;<br />
ad = new AddParameters();<br />
} <br />
<br />
private string Connect(out SqlConnection con)<br />
{<br />
try<br />
{<br />
con = new SqlConnection(connectionstring);<br />
con.Open();<br />
return "";<br />
}<br />
<br />
catch (Exception ex)<br />
{<br />
con = null;<br />
return ex.Message.ToString();<br />
}<br />
}<br />
<br />
public string StoredProcedureName<br />
{ <br />
get<br />
{<br />
return StoredProcedure;<br />
}<br />
set<br />
{<br />
StoredProcedure = value;<br />
}<br />
}<br />
public string BindingWithControl(Control ctl, string ValueMember, string DisplayMember)<br />
{<br />
string message = Connect(out con);<br />
if (message == "")<br />
{<br />
message = GetDataSet(con, ref ds);<br />
if (message == "")<br />
{<br />
BindControl(ctl, ds, DisplayMember, ValueMember);<br />
con.Close();<br />
return "";<br />
}<br />
else<br />
{<br />
con.Close();<br />
return message;<br />
}<br />
}<br />
else<br />
{<br />
con.Close();<br />
return message;<br />
}<br />
}<br />
<br />
public void BindControl(Control ctl, DataSet ds, string DisplayMember, string ValueMember)<br />
{<br />
if (ctl is RadioButtonList)<br />
{<br />
RadioButtonList chk;<br />
chk = (RadioButtonList)ctl;<br />
chk.DataTextField = DisplayMember;<br />
chk.DataValueField = ValueMember;<br />
chk.DataSource = ds.Tables[0];<br />
chk.DataBind();<br />
}<br />
if (ctl is CheckBoxList)<br />
{<br />
CheckBoxList chk;<br />
chk = (CheckBoxList)ctl;<br />
chk.DataTextField = DisplayMember;<br />
chk.DataValueField = ValueMember;<br />
chk.DataSource = ds.Tables[0];<br />
chk.DataBind();<br />
}<br />
if (ctl is DropDownList)<br />
{<br />
DropDownList ddl;<br />
ddl = (DropDownList)ctl;<br />
if (DisplayMember != "")<br />
{<br />
ddl.DataTextField = DisplayMember;<br />
}<br />
if (ValueMember != "")<br />
{<br />
ddl.DataValueField = ValueMember;<br />
} <br />
ddl.DataSource = ds;<br />
ddl.DataBind();<br />
}<br />
if (ctl is GridView)<br />
{<br />
GridView gv;<br />
gv = (GridView)ctl;<br />
if (ds.Tables.Count == 0)<br />
{<br />
return;<br />
}<br />
gv.ID = ctl.ID;<br />
gv.DataSource = ds;<br />
gv.DataBind();<br />
}<br />
if (ctl is Repeater)<br />
{<br />
Repeater gv;<br />
gv = (Repeater)ctl;<br />
if (ds.Tables.Count == 0)<br />
{<br />
return;<br />
}<br />
gv.ID = ctl.ID;<br />
gv.DataSource = ds;<br />
gv.DataBind();<br />
}<br />
if (ctl is DataList)<br />
{<br />
DataList gv;<br />
gv = (DataList)ctl;<br />
if (ds.Tables.Count == 0)<br />
{<br />
return;<br />
}<br />
gv.ID = ctl.ID;<br />
gv.DataSource = ds;<br />
gv.DataBind();<br />
}<br />
}<br />
<br />
public string GetDataSet(SqlConnection con, ref DataSet ds)<br />
{<br />
try<br />
{<br />
<br />
cmd = new SqlCommand();<br />
cmd.Connection = con;<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.CommandText = StoredProcedure;<br />
if (ad != null)<br />
{<br />
if (ad.p[0] != null)<br />
{<br />
if (ad.p.Length != 0)<br />
ReturnSqlCommand(ref cmd, ad.p);<br />
}<br />
}<br />
ds = new DataSet();<br />
<br />
sqlad = new SqlDataAdapter(cmd);<br />
sqlad.Fill(ds);<br />
if (ad.p[0] == null)<br />
{<br />
return "";<br />
}<br />
for (int count = 0; count < ad.p.Length; count++)<br />
{<br />
if (ad.p[count] == null)<br />
continue;<br />
if (ad.p[count].param.Direction == ParameterDirection.Output)<br />
{<br />
ad.p[count].param.SqlValue = cmd.Parameters[count].Value.ToString();<br />
}<br />
if (ad.p[count].param.Direction == ParameterDirection.InputOutput)<br />
{<br />
ad.p[count].param.SqlValue = cmd.Parameters[count].Value.ToString();<br />
}<br />
} <br />
return "";<br />
}<br />
catch (Exception ex)<br />
{<br />
return ex.Message.ToString(); <br />
}<br />
}<br />
<br />
private SqlCommand ReturnSqlCommand(ref SqlCommand cmd, AddParameters[] db)<br />
{<br />
for (int count = 0; count < db.Length; count++)<br />
{<br />
if (db[count].param.Direction == ParameterDirection.Input)<br />
{<br />
cmd.Parameters.AddWithValue(db[count].param.ParameterName, db[count].param.SqlDbType).Value = db[count].param.SqlValue;<br />
cmd.Parameters[count].SqlDbType = db[count].param.SqlDbType;<br />
}<br />
if (db[count].param.Direction == ParameterDirection.Output)<br />
{<br />
cmd.Parameters.AddWithValue(db[count].param.ParameterName, db[count].param.SqlDbType);<br />
cmd.Parameters[count].SqlDbType = db[count].param.SqlDbType;<br />
cmd.Parameters[count].Direction = ParameterDirection.Output;<br />
}<br />
if (db[count].param.Direction == ParameterDirection.InputOutput)<br />
{<br />
cmd.Parameters.AddWithValue(db[count].param.ParameterName, db[count].param.SqlDbType);<br />
cmd.Parameters[count].SqlDbType = db[count].param.SqlDbType;<br />
cmd.Parameters[count].Direction = ParameterDirection.InputOutput;<br />
cmd.Parameters[count].Size = 3000;<br />
}<br />
}<br />
return cmd;<br />
}<br />
<br />
public string returnScalarData()<br />
{<br />
SqlCommand cmd = new SqlCommand();<br />
SqlConnection con;<br />
Connect(out con);<br />
DataSet ds = new DataSet();<br />
cmd.Connection = con;<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.CommandText = StoredProcedure;<br />
if (ad != null)<br />
{<br />
if (ad.p != null)<br />
{<br />
if (ad.p.Length != 0)<br />
ReturnSqlCommand(ref cmd, ad.p);<br />
}<br />
<br />
}<br />
if (cmd.ExecuteScalar() == null)<br />
return null;<br />
else<br />
return cmd.ExecuteScalar().ToString().Trim();<br />
}<br />
<br />
public DataSet returndataset()<br />
{<br />
SqlCommand cmd = new SqlCommand();<br />
SqlConnection con;<br />
Connect(out con);<br />
DataSet ds = new DataSet();<br />
cmd.Connection = con;<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.CommandText = StoredProcedure;<br />
if (ad != null)<br />
{<br />
if (ad.p[0] != null)<br />
{<br />
if (ad.p.Length != 0)<br />
ReturnSqlCommand(ref cmd, ad.p);<br />
}<br />
}<br />
sqlad = new SqlDataAdapter(cmd);<br />
sqlad.Fill(ds);<br />
sqlad = null;<br />
return ds;<br />
}<br />
}<br />
}
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
Pankaj Garg wrote: written in my carrier
carrier
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
i meant career .Sorry for the spellings
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
No problem. But a quick spell check would always help before posting across to a wider audience and community.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Pankaj Garg wrote: string GetDataSet(SqlConnection con, ref DataSet ds)
Function is named GetDataSet() and it returns a string . Also I don't think ref is not needed here as DataSet is a class and passed always as reference.
Pankaj Garg wrote: catch (Exception ex)
{
return ex.Message.ToString();
}
}
This is bad. You should catch specific exception types, do cleanup and re-throw it. Also you are not disposing instances. You know most of the classes used here has a Dispose() method, call that when you finish using the instance. This will allow instance memory reclaiming.
|
|
|
|
|
Pankaj Garg wrote: According to me this is my Best code ever written in my carrier.
Change career! Its some of the worst data abstraction code Ive seen in my career!
eg/ what the hell is all this about (note: p is set to an array with 1 element):
Pankaj Garg wrote: public void ParameterFunction<T>(string ParameterName, T _ParameterValue, ParameterDirection ParameterDirection, SqlDbType ParameterType)
{
if (p[p.Length - 1] != null)
{
AddParameters[] temp = new AddParameters[p.Length];
p.CopyTo(temp, 0);
p = new AddParameters[p.Length + 1];
for (int i = 0; i < p.Length - 1; i++)
{
p[i] = temp[i];
}
p[p.Length - 1] = new AddParameters();
p[p.Length - 1].param.ParameterName = ParameterName;
p[p.Length - 1].param.Value = _ParameterValue;
p[p.Length - 1].param.Direction = ParameterDirection;
p[p.Length - 1].param.SqlDbType = ParameterType;
}
else
{
p[0] = new AddParameters();
p[0].param.ParameterName = ParameterName;
p[0].param.SqlValue = _ParameterValue;
p[0].param.Direction = ParameterDirection;
p[0].param.SqlDbType = ParameterType;
}
}
}
and this is just car-crash stuff. I shouldnt look, but at the same time I cant look away
public string GetDataSet(SqlConnection con, ref DataSet ds)
{
try
{
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = StoredProcedure;
if (ad != null)
{
if (ad.p[0] != null)
{
if (ad.p.Length != 0)
ReturnSqlCommand(ref cmd, ad.p);
}
}
ds = new DataSet();
sqlad = new SqlDataAdapter(cmd);
sqlad.Fill(ds);
if (ad.p[0] == null)
{
return "";
}
for (int count = 0; count < ad.p.Length; count++)
{
if (ad.p[count] == null)
continue;
if (ad.p[count].param.Direction == ParameterDirection.Output)
{
ad.p[count].param.SqlValue = cmd.Parameters[count].Value.ToString();
}
if (ad.p[count].param.Direction == ParameterDirection.InputOutput)
{
ad.p[count].param.SqlValue = cmd.Parameters[count].Value.ToString();
}
}
return "";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
Tell me, how do you call a stored procedure with more than 1 parameter?
modified on Monday, May 19, 2008 8:31 AM
|
|
|
|
|
Hello There,
I developed a website and uploaded it to the web but when i'm trying it it shows me the Error "Compiler Error Message: CS0246: The type or namespace name ...." .
When i want to add new class to the project Visual Studio 2005 recomended to add it under APP_CODE folder and i did.
i uploaded the website after compiling it using the copy web site method from website menu >> Copy Website option and then i used ftp manager to uploaded .
the code is running very well on my machine but online no.
i don't have any dll for these classes so i can add the referrence it's just normal .cs classes .
i don't know should i add anything to the web.config or modify something in the code ?
Asaad Mamoun
|
|
|
|
|
Hi all,
I am building one application where i want to do folowing
1) Open popup on button click
2) Pop up contains name textbox and search button and datagrid.
3) user type name in textbox and search result will comre in datagrid
I used modal popup ajax control (AnimationExtender)
New pop is properly loding with all controls but when i clicked on search button popup window automaticaly close.
I am not getting how to handel this?
so plz help me if anyone knows soln....
|
|
|
|
|
Hi,
You can put two button(Search N Close) one for search and another for closing popup
use UpdatePanel put both buttons in this and call .Hide() method of ModelPopup in code behind on button
click event.
see the sample impl.
.aspx coding
<asp:button runat="server" id="hiddenTargetControlForModalPopup" style="display: none">
<cc1:modalpopupextender runat="server" id="programmaticModalPopup" behaviorid="programmaticModalPopupBehavior">
TargetControlID="hiddenTargetControlForModalPopup" PopupControlID="programmaticPopup"
BackgroundCssClass="modalBackground" DropShadow="false" PopupDragHandleControlID="programmaticPopupDragHandle"
RepositionMode="RepositionOnWindowScroll">
<asp:panel runat="server" cssclass="modalPopup" id="programmaticPopup" style="display: none">
<asp:panel runat="server" id="programmaticPopupDragHandle">
<asp:label id="lblHeading" runat="server" text="Do you want to continue merging process?">
<asp:label id="lblMergeConfirm" runat="server">
<asp:updatepanel id="upnlModal" runat="server">
<asp:button id="btnOk" runat="server" text="Yes" cssclass="defaultButton" causesvalidation="false">
<asp:button id="btnClose" runat="server" text="Close" cssclass="defaultButton" causesvalidation="false">
Implement your logic for populating Gridview with appropriate search results in Search Button click event in code behind..
Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
Try
Me.programmaticModalPopup.Hide()
Catch ex As Exception
throw ex
End Try
End Sub
Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
Try
// implement logic to populate gridview with resultset.
// If you want to execute any logic when click on button that opens popup
// you put button ouside the updatepanel.
Catch ex As Exception
throw
End Try
End Sub
Check lines which are in bold format. I hope this will solve your problem.
if you get any problem in populating GridView then pls delete search button from updatepanel.
You can refer Ajaxtoolkit sample impl video for all ajaxtoolkit controls.
modified on Wednesday, May 28, 2008 10:21 AM
|
|
|
|
|
Hi all,
i used have this function for validate new user:
public bool ValidateNewUser(string strAlias, string strFirst, string strLast)
{
SqlConnection MyConn = new SqlConnection(ConfigurationSettings.AppSettings["MyOnlineShoppingConnectionString2"]);
SqlCommand MyCmd = new SqlCommand("sp_CheckForDuplicates", MyConn);
MyCmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter objParam3;
SqlParameter objReturnParam;
objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar);
objParam2 = MyCmd.Parameters.Add("@FirstName", SqlDbType.VarChar);
objParam3 = MyCmd.Parameters.Add("@LastName", SqlDbType.VarChar);
objReturnParam = MyCmd.Parameters.Add("@Duplicates", SqlDbType.Int);
objReturnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = strAlias;
objParam2.Value = strFirst;
objParam3.Value = strLast;
try
{
if (MyConn.State == ConnectionState.Closed)
{
MyConn.Open();
MyCmd.ExecuteNonQuery();
}
<big>if (objReturnParam.Value > 0)</big>
{
lblResult.Text = "UserName already exists or you are already a registered user!";
return false;
}
else
{
return true;
}
MyConn.Close();
}
catch (Exception ex)
{
lblError.Text = "Error Connecting to Database!";
}
}
but when i run this code this error is occured:
Operator '>' cannot to operands of type 'Object' and 'Int'
how i can resolve this error?
thank you,
Hoda
|
|
|
|
|
sorry for duplicating this massage,but i couldn't delete one of them.
Hoda
|
|
|
|
|
Saba02 wrote: i couldn't delete one of them.
Are you facing a specific error? Perhaps you can try posting a request for the same in 'Suggestions' forum so that a CP Administrator should help you with the same.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Hi There
If i understand your question very well ....
i think you should use
if (Convert.ToInt32(objReturnParam.Value) > 0)
try it
|
|
|
|
|
|
Hi all,
i used have this function for validate new user:
public bool ValidateNewUser(string strAlias, string strFirst, string strLast)
{
SqlConnection MyConn = new SqlConnection(ConfigurationSettings.AppSettings["MyOnlineShoppingConnectionString2"]);
SqlCommand MyCmd = new SqlCommand("sp_CheckForDuplicates", MyConn);
MyCmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter objParam3;
SqlParameter objReturnParam;
objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar);
objParam2 = MyCmd.Parameters.Add("@FirstName", SqlDbType.VarChar);
objParam3 = MyCmd.Parameters.Add("@LastName", SqlDbType.VarChar);
objReturnParam = MyCmd.Parameters.Add("@Duplicates", SqlDbType.Int);
objReturnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = strAlias;
objParam2.Value = strFirst;
objParam3.Value = strLast;
try
{
if (MyConn.State == ConnectionState.Closed)
{
MyConn.Open();
MyCmd.ExecuteNonQuery();
}
if (objReturnParam.Value > 0)
{
lblResult.Text = "UserName already exists or you are already a registered user!";
return false;
}
else
{
return true;
}
MyConn.Close();
}
catch (Exception ex)
{
lblError.Text = "Error Connecting to Database!";
}
}
but when i run this code this error is occured:
Operator '>' cannot to operands of type 'Object' and 'Int'
how i can resolve this error?
thank you,
Hoda
|
|
|
|
|
You might need to convert objReturnParam to an integer
|
|
|
|
|
Saba02 wrote: objReturnParam.Value
Can you pass this to Convert.ToInt32() ?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Saba02 wrote: if (objReturnParam.Value > 0)
{
lblResult.Text = "UserName already exists or you are already a registered user!";
return false;
}
You need to convert the parameter value to integer.
if (Convert.ToInt32(objReturnParam.Value) > 0)
{
lblResult.Text = "UserName already exists or you are already a registered user!";
return false;
}
|
|
|
|
|
Thank you for your responses
Hoda
|
|
|
|
|
I have put on some controls on page and i am using AJAX...
<code><table id="TABLE1" style="width: 100%">
<tr>
<td>
Item</td>
<td colspan="4">
<asp:dropdownlist id="DDL_Item" runat="server" datasourceid="Itemsource" datatextfield="description" datavaluefield="code">
</asp:dropdownlist>
<asp:sqldatasource id="Itemsource" runat="server" connectionstring=""><![CDATA[<%$ ConnectionStrings:Conn %>]]>"
SelectCommand="Fill_Price_Item_Dropdown" SelectCommandType="StoredProcedure"></asp:sqldatasource>
</td>
</tr>
<tr>
<td>
Date From:</td>
<td>
<table>
<tr>
<td><asp:textbox id="TextBox_Date_From" runat="server"></asp:textbox></td>
<td>
<img id="Btn1" src="../images/CalImage.gif" /></td>
</tr>
</table>
<cc1:calendarextender id="CalendarExtender1" runat="server" format="dd/MM/yyyy" popupbuttonid="Btn1">
targetcontrolid="TextBox_Date_From"></cc1:calendarextender>
</td>
<td>
</td>
<td>
To</td>
<td>
<table>
<tr>
<td>
<asp:textbox id="TextBox_Date_To" runat="server"></asp:textbox></td>
<td>
<img id="Btn2" src="../images/CalImage.gif" /></td>
</tr>
</table>
<cc1:calendarextender id="CalendarExtender2" runat="server" format="dd/MM/yyyy" popupbuttonid="Btn2">
targetcontrolid="TextBox_Date_To">
</cc1:calendarextender>
</td>
</tr>
<tr>
<td>
Zone</td>
<td colspan="4">
<asp:updatepanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:dropdownlist id="DDL_Zone" runat="server" datasourceid="Zone_src" datatextfield="Zone_Name" datavaluefield="Zone_Code" autopostback="True" onselectedindexchanged="DDL_Zone_SelectedIndexChanged">
</asp:dropdownlist><asp:sqldatasource id="Zone_src" runat="server" connectionstring=""><![CDATA[<%$ ConnectionStrings:Conn %>]]>"
SelectCommand="SELECT DISTINCT [Zone_Code], [Zone_Name] FROM [Zone_Master] WHERE ([isdeleted] = 0)">
<selectparameters>
<asp:parameter defaultvalue="0" name="isdeleted" type="Int32" />
</selectparameters>
</asp:sqldatasource>
</contenttemplate>
</asp:updatepanel>
</td>
</tr>
<tr>
<td>
State</td>
<td colspan="4">
<asp:updatepanel id="UpdatePanel2" runat="server">
<contenttemplate>
<asp:dropdownlist id="DDL_State" runat="server" datasourceid="State_src" datatextfield="State_Name" datavaluefield="State_Code">
</asp:dropdownlist>
<asp:sqldatasource id="State_src" runat="server" connectionstring=""><![CDATA[<%$ ConnectionStrings:Conn %>]]>"
SelectCommand="SELECT [State_Code], [State_Name] FROM [State_Master] WHERE ([Zone_Code] = @Zone_Code)">
<selectparameters>
<asp:controlparameter controlid="DDL_Zone" defaultvalue="0" name="Zone_Code" propertyname="SelectedValue">
Type="String" />
</asp:controlparameter></selectparameters>
</asp:sqldatasource>
</contenttemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="DDL_Zone" eventname="SelectedIndexChanged" />
</triggers>
</asp:updatepanel>
</td>
</tr>
<tr>
<td>
</td>
<td align="center" colspan="4">
<asp:button id="Button_Search" runat="server" text="Search" width="83px" /></td>
</tr>
</table></code>
on page load i m setting the default select option as follows..
<code><pre> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
DDL_Item.DataBind()
DDL_Zone.DataBind()
DDL_State.DataBind()
DDL_Item.Items.Insert(0, New ListItem("Select", "0"))
DDL_Zone.Items.Insert(0, New ListItem("Select", "0"))
DDL_State.Items.Insert(0, New ListItem("Select", "0"))
TextBox_Date_From.Text = Now.Date.ToString("dd/MM/yyyy")
TextBox_Date_To.Text = Now.Date.ToString("dd/MM/yyyy")
TextBox_Date_From.Attributes.Add("readonly", "readonly")
TextBox_Date_To.Attributes.Add("readonly", "readonly")
End If
End Sub</pre></code>
but i m unable to set the "Select" option for zone ddl. I mean that the option is present in the DDL but the second option is highlited always...
I also tried this
DDL_Zone.Items.FindByValue("0").Selected = True
but it didn`t help... what can be that prob
|
|
|
|
|
try this
DDL_Zone.Items.SelectedValue = "0" or
DDL_Zone.SelectedValue = DDL_Zone.Items.FindByText("0").Value
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
Do you mean that when someone clicks on the dropdownlist the select is not highlighted first or do you mean when someone clicks on the select value and then leaves the dropdown it doesnt store the select value?
|
|
|
|
|