Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i wrote textchanged event for combo box but its not working , If any alternative for this pls help me.

When combo box text is changed then i can enable the text boxes other wise put it in disable mode. but THis textchanged event is not fire when text is changed. Is it combox box can fire both the events or not.

<asp:ComboBox ID="cmbBatchno" OnSelectedIndexChanged="cmbBatchno_SelectedIndexChanged" OnTextChanged="cmbBatchno_textchange" ItemInsertLocation="Prepend" runat="server" AutoPostBack="True" DropDownStyle="Simple" AutoCompleteMode="Append">

public void cmbBatchno_SelectedIndexChanged(object sender, EventArgs e)
{

if (ViewState["BatchNo"] != null)
{
DataTable dtBatchNoDtls = (DataTable)ViewState["BatchNo"];
for (int i = 0; i < dtBatchNoDtls.Rows.Count; i++)
{
if (dtBatchNoDtls.Rows[i]["BatchNo"].ToString() == cmbBatchno.Text)
{
txtExpdate.Text = dtBatchNoDtls.Rows[i]["ExpDate"].ToString();
txtMRP.Text = dtBatchNoDtls.Rows[i]["MRP"].ToString();
txtRate.Text = dtBatchNoDtls.Rows[i]["Rate"].ToString();
if (txtExpdate.Text != "")
txtPacks.Focus();
else
txtExpdate.Focus();
break;
}
else
{
txtExpdate.Text = string.Empty;
txtMRP.Text = "";
txtRate.Text = "";
}
}
}
}


// this is method is not fired when text is changed.
public void cmbBatchno_textchange(object sender, EventArgs e)
{
if (ViewState["BatchNo"] != null)
{
DataTable dtBatchNoDtls = (DataTable)ViewState["BatchNo"];
for (int i = 0; i < dtBatchNoDtls.Rows.Count; i++)
{
if (cmbBatchno.Text == dtBatchNoDtls.Rows[i]["BatchNo"].ToString())
{
txtExpdate.Enabled = false;
txtMRP.Enabled = false;
break;
}
else
{
txtExpdate.Enabled = true;
txtMRP.Enabled = true;
txtExpdate.Text = string.Empty;
txtMRP.Text = "";
txtRate.Text = "";
}
}

}


}
Posted
Updated 20-Oct-13 20:31pm
v2
Comments
[no name] 21-Oct-13 2:08am    
very less information..what you are trying to do..??
MANI 14 21-Oct-13 2:13am    
When combo box text is changed then i can enable the text boxes other wise put it in disable mode. but THis textchanged event is not fire..

<asp:ComboBox ID="cmbBatchno" OnSelectedIndexChanged="cmbBatchno_SelectedIndexChanged" OnTextChanged="cmbBatchno_textchange" ItemInsertLocation="Prepend" runat="server" AutoPostBack="True" DropDownStyle="Simple" AutoCompleteMode="Append">

public void cmbBatchno_SelectedIndexChanged(object sender, EventArgs e)
{

if (ViewState["BatchNo"] != null)
{
DataTable dtBatchNoDtls = (DataTable)ViewState["BatchNo"];
for (int i = 0; i < dtBatchNoDtls.Rows.Count; i++)
{
if (dtBatchNoDtls.Rows[i]["BatchNo"].ToString() == cmbBatchno.Text)
{
txtExpdate.Text = dtBatchNoDtls.Rows[i]["ExpDate"].ToString();
txtMRP.Text = dtBatchNoDtls.Rows[i]["MRP"].ToString();
txtRate.Text = dtBatchNoDtls.Rows[i]["Rate"].ToString();
if (txtExpdate.Text != "")
txtPacks.Focus();
else
txtExpdate.Focus();
break;
}
else
{
txtExpdate.Text = string.Empty;
txtMRP.Text = "";
txtRate.Text = "";
}
}
}
}

public void cmbBatchno_textchange(object sender, EventArgs e)
{
if (ViewState["BatchNo"] != null)
{
DataTable dtBatchNoDtls = (DataTable)ViewState["BatchNo"];
for (int i = 0; i < dtBatchNoDtls.Rows.Count; i++)
{
if (cmbBatchno.Text == dtBatchNoDtls.Rows[i]["BatchNo"].ToString())
{
txtExpdate.Enabled = false;
txtMRP.Enabled = false;
break;
}
else
{
txtExpdate.Enabled = true;
txtMRP.Enabled = true;
txtExpdate.Text = string.Empty;
txtMRP.Text = "";
txtRate.Text = "";
}
}

}


}
JoCodes 21-Oct-13 2:26am    
Please update the code as part of your question to make it more relevent
JoCodes 21-Oct-13 2:38am    
Is your cmbBatchno_SelectedIndexChanged event firing?
MANI 14 21-Oct-13 2:40am    
yes cmbBatchno_selectedIndexChanged is firing. If selected index text is changed in combo box then cmbBatchno_TextChanged event is not fire.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900