|
hii all...
i hav populated the two dropdown lists from database.
according to the item selected in the dropdown i want to change
the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox.
plz reply..
the code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateDDL1();
PopulateDDL2();
}
}
public void PopulateDDL1()
{
SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString));
cmd.Connection.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataValueField = "VendorID";
DropDownList1.DataTextField = "VendorID";
DropDownList1.DataBind();
cmd.Connection.Close();
}
public void PopulateDDL2()
{
SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString));
cmd.Connection.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
DropDownList2.DataSource = dr;
DropDownList2.DataValueField = "ProductID";
DropDownList2.DataTextField = "ProductID";
DropDownList2.DataBind();
cmd.Connection.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')";
SqlCommand cmd = new SqlCommand(str, conn);
SqlDataReader dr = null;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr["VendorName"].ToString();
}
conn.Close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')";
SqlCommand cmd = new SqlCommand(str, conn);
SqlDataReader dr = null;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox3.Text = dr["ProductName"].ToString();
}
conn.Close();
}
|
|
|
|
|
check whether you have given autopostback property to both the dropdown
|
|
|
|
|
yaa i hav made both dropdown autopostback property to true....
|
|
|
|
|
|
your code seems to be fine.... jus check whether u have values in the database......
|
|
|
|
|
Make sure you have wired the event up properly in your aspx page, i.e.
<asp:dropdownlist id="DropDownList2" runat="server" autopostback="true" onselectedindexchanged="DropDownList2_SelectedIndexChanged">
Also, put a breakpoint at the start of your DropDownList2_SelectedIndexChanged method to see if it is being called at all.
|
|
|
|
|
Is the AutoPostBack property of that dropdown set to True?
MP
|
|
|
|
|
|
i have done the same thing which u want i just use daset instead of datareader try it
protected void Page_Load(object sender, EventArgs e)
{
DAL Helper = new DAL();
Helper.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Coupon Management.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
string query = "select CouponName from CouponType";
ds = Helper.ExecuteDataSet(CommandType.Text, query, null);
if (!IsPostBack)
{
ddlCType.DataSource = ds;
ddlCType.DataValueField = "CouponName";
ddlCType.DataTextField = "CouponName";
ddlCType.DataSourceID = String.Empty;
}
}
protected DataSet GetData(string sqlCommand)
{
da1 = new SqlDataAdapter(sqlCommand, cnx );
ds = new DataSet();
da1.Fill(ds );
return ds ;
}
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
cnx.Open();
SqlCommand ddlcmd = new SqlCommand();
commandText = "SELECT MAX(CouponTransaction.SerialEnd),CouponType.Price FROM CouponType INNER JOIN CouponTransaction ON CouponType.CouponTypeID = CouponTransaction.CouponTypeID WHERE CouponType.CouponName= '" + ddlCType.SelectedValue + "'GROUP BY CouponType.Price";
ds = new DataSet();
ds = GetData(commandText);
if (ds.Tables[0].Rows.Count!=0 )
{
txtSFrom.Text = ds.Tables[0].Rows[0][0].ToString();
Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
cnx.Close();
}
}
|
|
|
|
|
thanks ....
|
|
|
|
|
|
hi
I have windows vista and
when I debug my website project in visual studio,
my browser doesn't run.
after that i checked my IIS in control panel but again browser doesn't work.
THX.
|
|
|
|
|
you mean to say, You are not able to debug Asp.Net application?
|
|
|
|
|
HI
Thanks for your attention
I mean that when i debug my website,IE said "can not find server".
|
|
|
|
|
i have a dropdownlist which a different values on its textchanged i want to populate two textboxs. one to show Maximum Serial end and another show Serial End.
when i select 3 value in textbox it works as i like. but other than 3 i slect any value it show error There is not row at position 0
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
cnx.Open();
SqlCommand ddlcmd = new SqlCommand();
commandText = "SELECT MAX(CouponTransaction.SerialEnd),CouponType.Price FROM CouponType INNER JOIN CouponTransaction ON CouponType.CouponTypeID = CouponTransaction.CouponTypeID WHERE CouponType.CouponName= '" + ddlCType.SelectedValue + "'GROUP BY CouponType.Price";
ds = new DataSet();
ds = GetData(commandText);
txtSFrom.Text =ds.Tables[0].Rows[0][0].ToString();
Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
cnx.Close();
}
|
|
|
|
|
ds = new DataSet();
ds = GetData(commandText);
if(ds.rows.count !=0)
{
txtSFrom.Text =ds.Tables[0].Rows[0][0].ToString();
Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
}
cnx.Close();
|
|
|
|
|
it show error in if statement that Doesn't contain definition for Rows"
|
|
|
|
|
sorry,
change it as
if(ds.Tables[0].Rows.count)
|
|
|
|
|
thnx its working thank u very much
|
|
|
|
|
I suggest you to always check count before fetching indexed elements.
if(ds.Tables.count >0)
{
if(ds.Tables[0].Rows.count > 0)
{
if(ds.Tables[0].Columns.Count >=2)
{
txtSFrom.Text = ds.Tables[0].Rows[0][0].ToString();
Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
}
}
}
like this.
|
|
|
|
|
|
Cheers
|
|
|
|
|
Hi all,
Im checking the password strength using JS. It works fine in IE but not in Mozila . Can any one solve my problem please. Here is the script.
<script language="javascript" type ="text/javascript">
function check_password_safety(pwd)
{
var msg = "";
var len= pwd.length;
var i;
var has_letter = new RegExp("[a-z]");
var has_caps = new RegExp("[A-Z]");
var has_numbers = new RegExp("[0-9]");
var has_symbols = new RegExp("\\W");
var pointsLetter=0;
var pointsCaps=0;
var pointsNumbers=0;
var pointsSpecials=0;
for(i=0;i<len;i++)
{
var x=pwd.charAt(i);
if(has_letter.test(x))
{
++pointsLetter;
}
else if(has_caps.test(x))
{
++pointsCaps;
}
else if(has_numbers.test(x))
{
++pointsNumbers;
}
else if(has_symbols.test(x))
{
++pointsSpecials;
}
}
if(len>6)
{
if(pointsLetter>0 && pointsCaps==0 && pointsNumbers==0 && pointsSpecials==0 && len>12)
{
password_info.innerHTML = "Very Week";
password_info.className='Style_VeryWeek';
}
if(pointsLetter>0 && pointsCaps==0 && pointsNumbers==0 && pointsSpecials==0 && len<12)
{
password_info.innerHTML = "Week";
password_info.className='Style_Week';
}
if(pointsLetter==0 && pointsCaps==0 && pointsNumbers>0 && pointsSpecials==0)
{
password_info.innerHTML = "Week";
password_info.className='Style_Week';
}
if(pointsLetter==0 && pointsCaps>0 && pointsNumbers==0 && pointsSpecials==0)
{
password_info.innerHTML = "Week";
password_info.className='Style_Week';
}
if(pointsLetter==0 && pointsCaps==0 && pointsNumbers==0 && pointsSpecials>0)
{
password_info.innerHTML = "Week";
password_info.className='Style_Week';
}
if(pointsLetter>0 && pointsCaps==0 && pointsNumbers>0 && pointsSpecials==0)
{
password_info.innerHTML = "Medium";
password_info.className='Style_Medium';
}
if(pointsLetter>0 && pointsCaps==0 && pointsNumbers==0 && pointsSpecials>0)
{
password_info.innerHTML = "Strong";
password_info.className='Style_Strong';
}
if(pointsLetter>0 && pointsCaps>0 && pointsNumbers==0 && pointsSpecials==0)
{
password_info.innerHTML = "Medium";
password_info.className='Style_Medium';
}
if(pointsLetter>0 && pointsCaps>0 && pointsNumbers>0 && pointsSpecials==0)
{
password_info.innerHTML = "Strong";
password_info.className='Style_Strong';
}
if(pointsLetter>0 && pointsCaps>0 && pointsNumbers==0 && pointsSpecials>0)
{
password_info.innerHTML = "Strong";
password_info.className='Style_Strong';
}
if(pointsLetter>0 && pointsCaps>0 && pointsNumbers>0 && pointsSpecials>0)
{
password_info.innerHTML = "Very Strong";
password_info.className='Style_VeryStrong';
}
if(pointsLetter>0 && pointsCaps==0 && pointsNumbers>0 && pointsSpecials>0)
{
password_info.innerHTML = "Very Strong";
password_info.className='Style_VeryStrong';
}
}
else
{
if(len!=0)
{
password_info.innerHTML ="Minimum Length 6 Charecters";
password_info.className='Style_Minimum';
}
else
{
password_info.innerHTML ="Type Password";
password_info.className='Style_Normal';
}
}
}
</script>
|
|
|
|
|
if i am not wrong!!!!! some of the script will not work in Mozila.....
|
|
|
|
|
First try to find out with the help of Alert() that which line of code is not working so can easily help you.
|
|
|
|