Brian
asked on
CheckBoxList_SelectedIndexChanged Problem
Hello Experts,
I have the following HTML and CodeBehind below that works ok. But the little problem that I'm facing is that if someone clicks on the actual CheckBox square then it runs the CheckBoxList_SelectedIndex Changed fine.
But if someone just clicks on the name/label of the CheckBox square value then the CheckBoxList_SelectedIndex Changed does not run.
Any idea how I can make the CheckBoxList_SelectedIndex Changed Event fire if the actual name/label is selected?
HTML:
CodeBehind:
protected void Page_Load(object sender, EventArgs e)
{
txtCurrentlyReceiveOtherIn fo.Visible = false;
lblCurrentlyReceiveExplain .Visible = false;
RetrieveCurrentlyReceieveD ata();
}
}
protected void RetrieveCurrentlyReceieveD ata()
{
DataTable dtCurrentlyReceiveValues = new DataTable();
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["TM F"].Connec tionString );
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "RetrieveCurrentlyReceiveD ata";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
adp.Fill(dtCurrentlyReceiv eValues);
try
{
conn.Open();
cblCurrentlyReceiveValues. DataSource = dtCurrentlyReceiveValues;
cblCurrentlyReceiveValues. DataValueF ield = "cr_id";
cblCurrentlyReceiveValues. DataTextFi eld = "cr_name";
cblCurrentlyReceiveValues. DataBind() ;
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
protected void cblCurrentlyReceiveValues_ SelectedIn dexChanged (object sender, EventArgs e)
{
var strtext = cblCurrentlyReceiveValues. SelectedIn dex.ToStri ng();
if (cblCurrentlyReceiveValues .SelectedI ndex != -1)
{
strtext = cblCurrentlyReceiveValues. SelectedIt em.Text;
}
if (strtext == "Other Government Assistance")
{
if (cblCurrentlyReceiveValues .SelectedI tem.Select ed)
{
txtCurrentlyReceiveOtherIn fo.Visible = true;
lblCurrentlyReceiveExplain .Visible = true;
}
else
{
txtCurrentlyReceiveOtherIn fo.Visible = false;
lblCurrentlyReceiveExplain .Visible = false;
}
}
else
{
txtCurrentlyReceiveOtherIn fo.Visible = false;
lblCurrentlyReceiveExplain .Visible = false;
}
}
I have the following HTML and CodeBehind below that works ok. But the little problem that I'm facing is that if someone clicks on the actual CheckBox square then it runs the CheckBoxList_SelectedIndex
But if someone just clicks on the name/label of the CheckBox square value then the CheckBoxList_SelectedIndex
Any idea how I can make the CheckBoxList_SelectedIndex
HTML:
<asp:Label ID="lblCurrentlyReceive" runat="server" CssClass="formlabel" Text="Do you currently receive:"></asp:Label>
<asp:CheckBoxList ID="cblCurrentlyReceiveValues" OnSelectedIndexChanged="cblCurrentlyReceiveValues_SelectedIndexChanged" runat="server" AutoPostBack="true"></asp:CheckBoxList>
<asp:Label ID="lblCurrentlyReceiveExplain" runat="server" Text="Explain"></asp:Label>
<asp:TextBox ID="txtCurrentlyReceiveOtherInfo" runat="server"></asp:TextBox>
CodeBehind:
protected void Page_Load(object sender, EventArgs e)
{
txtCurrentlyReceiveOtherIn
lblCurrentlyReceiveExplain
RetrieveCurrentlyReceieveD
}
}
protected void RetrieveCurrentlyReceieveD
{
DataTable dtCurrentlyReceiveValues = new DataTable();
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "RetrieveCurrentlyReceiveD
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
adp.Fill(dtCurrentlyReceiv
try
{
conn.Open();
cblCurrentlyReceiveValues.
cblCurrentlyReceiveValues.
cblCurrentlyReceiveValues.
cblCurrentlyReceiveValues.
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
protected void cblCurrentlyReceiveValues_
{
var strtext = cblCurrentlyReceiveValues.
if (cblCurrentlyReceiveValues
{
strtext = cblCurrentlyReceiveValues.
}
if (strtext == "Other Government Assistance")
{
if (cblCurrentlyReceiveValues
{
txtCurrentlyReceiveOtherIn
lblCurrentlyReceiveExplain
}
else
{
txtCurrentlyReceiveOtherIn
lblCurrentlyReceiveExplain
}
}
else
{
txtCurrentlyReceiveOtherIn
lblCurrentlyReceiveExplain
}
}
ASKER
Hi quicksilver17,
Can you tell me or show me what I need to put in the TextChanged Event?
Can you tell me or show me what I need to put in the TextChanged Event?
i tried with the TextChanged but its not working
sorry but i thought that i can return the clicked text from the TextChanged EventArgs e
i'm sorry
sorry but i thought that i can return the clicked text from the TextChanged EventArgs e
i'm sorry
have you tried with other browsers too?
if i add items manually, it works
if i add items manually, it works
ASKER
No, even if it did I can't have it solely rely on just certain browsers.
When you debug the program which one is the value of the strtext on this line when you click on the text portion of the checkbox??
var strtext = cblCurrentlyReceiveValues. SelectedIn dex.ToStri ng();
var strtext = cblCurrentlyReceiveValues.
ASKER
@k-designers,
Hi, I set a breakpoint on the line that you suggested on your last post but when I ran my application that breakpoint was never hit, in other words there wasn't a value for strtext.
Below is the code that I'm using as mentioned in original post.
Hi, I set a breakpoint on the line that you suggested on your last post but when I ran my application that breakpoint was never hit, in other words there wasn't a value for strtext.
Below is the code that I'm using as mentioned in original post.
protected void cblCurrentlyReceiveValues_SelectedIndexChanged(object sender, EventArgs e)
{
var strtext = cblCurrentlyReceiveValues.SelectedIndex.ToString();
if (cblCurrentlyReceiveValues.SelectedIndex != -1)
{
strtext = cblCurrentlyReceiveValues.SelectedItem.Text;
}
if (strtext == "Other Government Assistance")
{
if (cblCurrentlyReceiveValues.SelectedItem.Selected)
{
txtCurrentlyReceiveOtherInfo.Visible = true;
lblCurrentlyReceiveExplain.Visible = true;
}
else
{
txtCurrentlyReceiveOtherInfo.Visible = false;
lblCurrentlyReceiveExplain.Visible = false;
}
}
else
{
txtCurrentlyReceiveOtherInfo.Visible = false;
lblCurrentlyReceiveExplain.Visible = false;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.sourceasp.net/example548/CheckBoxList-TextChanged-Event-C-Sharp.aspx
hope it helps