louise_8
asked on
checkbox control parameter not working all the time
Hi,
Im having an issue with a checkbox control parameter.
It seems to be ok when the page first runs (checked - value A)
but once its unchecked it keeps that value..
When the page loads, the checkbox is selected
(I assign it to a page parameter, hdActiveGroups) and the value relating to it 'A' is sent to the datasource correctly
Once I uncheck it, it correctly sends Z to the datasource.
Then when I check it again (value A) it seems to send value Z to the datasource.. ie I get results as if Z was passed (unchecked)
(even though hdActiveGroups displays as A..)
Realistically I just need a way for the checkbox parameter to be A if checked, Z if unchecked and for it refresh the ddl when checkchanged
code:
<asp:textbox ID="hdActiveGroups" runat="server" />
<asp:CheckBox ID="chkActiveGroups" runat="server" Checked="true" OnCheckedChanged="Check_Gr oupStatus" AutoPostBack="true"/>
<asp:SqlDataSource ID="SqlDataSourceGroupDisc " runat="server" ConnectionString="<%$ ConnectionStrings:Connecti onString %>"
SelectCommand="aspGetDGrou ps" SelectCommandType="StoredP rocedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="123" Name="iClientid" QueryStringField="iClienti d" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="iGroupDiscountid" Type="Int32" />
<asp:ControlParameter ControlID="hdActiveGroups" Name="cStatus" Type="String" />
</SelectParameters>
codebehind
</asp:SqlDataSource>
protected void Page_Load(object sender, EventArgs e)
{
if (chkActiveGroups.Checked)
{
hdActiveGroups.Text = "A";
}
else
{
hdActiveGroups.Text = "Z";
}
etc
}
protected void Check_GroupStatus(Object sender, EventArgs e)
{
if (chkActiveGroups.Checked)
{
hdActiveGroups.Text = "A";
}
else
{
hdActiveGroups.Text = "Z";
}
ddlGroupDiscount.DataBind( );
}
Im having an issue with a checkbox control parameter.
It seems to be ok when the page first runs (checked - value A)
but once its unchecked it keeps that value..
When the page loads, the checkbox is selected
(I assign it to a page parameter, hdActiveGroups) and the value relating to it 'A' is sent to the datasource correctly
Once I uncheck it, it correctly sends Z to the datasource.
Then when I check it again (value A) it seems to send value Z to the datasource.. ie I get results as if Z was passed (unchecked)
(even though hdActiveGroups displays as A..)
Realistically I just need a way for the checkbox parameter to be A if checked, Z if unchecked and for it refresh the ddl when checkchanged
code:
<asp:textbox ID="hdActiveGroups" runat="server" />
<asp:CheckBox ID="chkActiveGroups" runat="server" Checked="true" OnCheckedChanged="Check_Gr
<asp:SqlDataSource ID="SqlDataSourceGroupDisc
SelectCommand="aspGetDGrou
<SelectParameters>
<asp:QueryStringParameter DefaultValue="123" Name="iClientid" QueryStringField="iClienti
<asp:Parameter DefaultValue="0" Name="iGroupDiscountid" Type="Int32" />
<asp:ControlParameter ControlID="hdActiveGroups"
</SelectParameters>
codebehind
</asp:SqlDataSource>
protected void Page_Load(object sender, EventArgs e)
{
if (chkActiveGroups.Checked)
{
hdActiveGroups.Text = "A";
}
else
{
hdActiveGroups.Text = "Z";
}
etc
}
protected void Check_GroupStatus(Object sender, EventArgs e)
{
if (chkActiveGroups.Checked)
{
hdActiveGroups.Text = "A";
}
else
{
hdActiveGroups.Text = "Z";
}
ddlGroupDiscount.DataBind(
}
ASKER
Thanks for your help
I think the issue is AppendDataBoundItems="true ".. its just adding the items each time I check the checkbox.. if I change to AppendDataBoundItems="fals e" it works but then I lose the itel Please select value=0
any ideas?
I think the issue is AppendDataBoundItems="true
any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
My ddl binds when the page is loaded
so I've put the line ddlGroupDiscount.Items.Ins ert(0, new ListItem("Please Select", "0")); in the page load however it doesnt add the item
Any ideas and I assume I dont to change AppendDataBoundItems="true " beforehand?
My ddl binds when the page is loaded
so I've put the line ddlGroupDiscount.Items.Ins
Any ideas and I assume I dont to change AppendDataBoundItems="true
ASKER
I put the code in the if !postback with AppendDataBoundItems="true " and it worked thanks
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
if (chkActiveGroups.Checked)
{
hdActiveGroups.Text = "A";
}
else
{
hdActiveGroups.Text = "Z";
}
etc
}
}