Showing posts with label checkbox. Show all posts
Showing posts with label checkbox. Show all posts

Thursday, March 29, 2012

Set CheckBox or Radio in repeater with if statement

Hi,
Attempting to display a questions list in my aspx page with the help of a
repeater.
This repeater displays each question (Label and picture) and each answer in
a nested repeater.
My problem is that each question can have ONE good answer or SEVERAL.
If the question has just one good answer, I want my answers displayed with
radio buttons.
In the other case, with checkbox.
is It Possible ?
Thks for help.Yes, but you'll most likely need to implement the logic in the ItemDataBound
event. This will let you define a placeholder in the itemTemplate which you
can then fill and dynamically create the checkbox/radiolist. You can find
out more at: http://www.openmymind.net/databinding/index.html
karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Mick" <saulot@.libertysurf.fr> wrote in message
news:41da537a$0$21436$636a15ce@.news.free.fr...
> Hi,
> Attempting to display a questions list in my aspx page with the help of a
> repeater.
> This repeater displays each question (Label and picture) and each answer
in
> a nested repeater.
> My problem is that each question can have ONE good answer or SEVERAL.
> If the question has just one good answer, I want my answers displayed with
> radio buttons.
> In the other case, with checkbox.
> is It Possible ?
> Thks for help.
>
>

Set CheckBox or Radio in repeater with if statement

Hi,
Attempting to display a questions list in my aspx page with the help of a
repeater.
This repeater displays each question (Label and picture) and each answer in
a nested repeater.

My problem is that each question can have ONE good answer or SEVERAL.
If the question has just one good answer, I want my answers displayed with
radio buttons.
In the other case, with checkbox.

is It Possible ?

Thks for help.Yes, but you'll most likely need to implement the logic in the ItemDataBound
event. This will let you define a placeholder in the itemTemplate which you
can then fill and dynamically create the checkbox/radiolist. You can find
out more at: http://www.openmymind.net/databinding/index.html

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Mick" <saulot@.libertysurf.fr> wrote in message
news:41da537a$0$21436$636a15ce@.news.free.fr...
> Hi,
> Attempting to display a questions list in my aspx page with the help of a
> repeater.
> This repeater displays each question (Label and picture) and each answer
in
> a nested repeater.
> My problem is that each question can have ONE good answer or SEVERAL.
> If the question has just one good answer, I want my answers displayed with
> radio buttons.
> In the other case, with checkbox.
> is It Possible ?
> Thks for help.

Set checkbox in datagrid manually/through code

I have a numeric Oracle field which stores -1 for true and 0 for
false. I am trying to populate a checkbox in a datagrid. In my SQL
statement, I used the Decode function so that when it populates the
dataset that I would store the string 'true' and 'false' rather than a
numeric value. I did this because I thought it would make it easier
to actually set the value in the checkbox. Anyway, I bind the dataset
to the datagrid. In my HTML code, the checkbox is contained in a
templatecolumn:

<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%#
(bool) DataBinder.Eval(Container.DataItem,
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox
However, this will not work. It complains that "Specified cast is not
valid."

I have even tried it without the "(bool)" cast and it still didn't
work.

The data in my database has the value stored as either a -1 or 0. In
either case, I just want to set the check box to checked or unchecked.
I was even wondering if I needed to use one of the d atagrid's events
to do this.

Any ideas or help is appreciated.

Thanks,
MartySome suggestions

Try using a helper function to interpret your -1 or 0 instead of adjusting your recordset to return true or false

In your codebehind

protected bool GetCheckBoxSetting(object myObj

int myInt = Convert.ToInt16(myObj)
return (myInt == -1)

Then in your aspx

<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
GetCheckBoxSetting(DataBinder.Eval(Container.DataI tem, "strainer_on_fuel_line_bool")) %>' Enabled="False"></asp:CheckBox

If returning bool doesn't set the checkbox checked property correctly then try returning a string from GetCheckBoxSetting method

protected string GetCheckBoxSetting(object myObj

int myInt = Convert.ToInt16(myObj)
if (myInt == -1
return "true"
els
return "false"

HTH
Suresh

-- Marty wrote: --

I have a numeric Oracle field which stores -1 for true and 0 fo
false. I am trying to populate a checkbox in a datagrid. In my SQ
statement, I used the Decode function so that when it populates th
dataset that I would store the string 'true' and 'false' rather than
numeric value. I did this because I thought it would make it easie
to actually set the value in the checkbox. Anyway, I bind the datase
to the datagrid. In my HTML code, the checkbox is contained in
templatecolumn

<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
(bool) DataBinder.Eval(Container.DataItem
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox

However, this will not work. It complains that "Specified cast is no
valid.

I have even tried it without the "(bool)" cast and it still didn'
work

The data in my database has the value stored as either a -1 or 0. I
either case, I just want to set the check box to checked or unchecked
I was even wondering if I needed to use one of the d atagrid's event
to do this

Any ideas or help is appreciated

Thanks,
Mart
It worked, thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Set checkboxs to be checked dynamically

hi,
I retrieve checkbox ids from a querystring on a page. Now I need to set the checkboxs to be checked on that page retrieving the ids from the querystring. How do I go about it?

Need some working code please

-vjI tired this...but no luck!!!!


dim ctrl as New HtmlInputCheckBox()
cur_choiceArray = split(request.QueryString("edit_item"), "," )
for i = Lbound(cur_choiceArray) to Ubound(cur_choiceArray)
ctrl = CType(cur_choiceArray(i), HtmlInputCheckBox)
ctrl.Checked=True
next

WHat am i doing wrong here?!
hi rveejay,

you could try like this:

Dim MyControlName As String = Request.QueryString("id")
CType(Me.FindControl(MyControlName), CheckBox).Checked = True

Regards
Richard Bean

Thursday, March 22, 2012

Set javascript value OnCheckedChanged

Hi,

I have a AutoPostBack checkbox and need to set a value bSubmitted =
true when the checkbox is checked in order to prevent a warning message
appearing notifying the user they are navigating away from the page.

I have been trying to add the following in the <script> section of the
<HEAD> section:

addNewSurgeonChkBx.Attributes.Add("onclick","javascript:bSubmitted=true;");

But it does not seem to work, I still get the error message.

I have also tried to put it on the onLoad section of the C# CodeBehind,
here though it surpresses the error message for all controls, not just
the checkbox.

Any ideas of how to fix this?

Thanks.How about letting the JavaScript that pops up the notification check if the
checkbox is checked.

So where is says:

Confirm('Are you sure you want to navigate away from this page');

change that too

if(!Document.GetElementById('addNewSurgeonChkBx'). Checked)
Confirm('Are you sure you want to navigate away from this page');

Is that what you looking for?

"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123775711.123436.307480@.g43g2000cwa.googlegr oups.com...
> Hi,
> I have a AutoPostBack checkbox and need to set a value bSubmitted =
> true when the checkbox is checked in order to prevent a warning message
> appearing notifying the user they are navigating away from the page.
> I have been trying to add the following in the <script> section of the
> <HEAD> section:
> addNewSurgeonChkBx.Attributes.Add("onclick","javascript:bSubmitted=true;");
> But it does not seem to work, I still get the error message.
> I have also tried to put it on the onLoad section of the C# CodeBehind,
> here though it surpresses the error message for all controls, not just
> the checkbox.
> Any ideas of how to fix this?
> Thanks.
Thanks, tried that but no luck. It stops the script from working for
all controls on the page!? Think it errored, so it could have been the
way i added it. Here's what I had:

function checkFormStatus(oForm)
{
if(isDirty(oForm))

if(!Document.GetElementById('addNewSurgeonChkBx'). Checked)
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}

Here's the full original code, if that might give anymore ideas:

// Warns user before page unload
function checkFormStatus(oForm)
{
if(isDirty(oForm))
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}

var bSubmitted=false;
function isDirty(oForm)
{
if(bSubmitted) return false;
var iNumElems = oForm.elements.length;
for (var i=0;i<iNumElems;i++)
{
var oElem = oForm.elements[i];

if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
{
if (oElem.value != oElem.defaultValue) return true;
}
else if ("checkbox" == oElem.type || "radio" == oElem.type)
{
if (oElem.checked != oElem.defaultChecked) return true;
}
else if ("SELECT" == oElem.tagName)
{
var oOptions = oElem.options;
var iNumOpts = oOptions.length;
for (var j=0;j<iNumOpts;j++)
{
var oOpt = oOptions[j];
if (oOpt.selected != oOpt.defaultSelected) return true;
}
}
}
return false;
}

It can be disadbled easily with the submit button by adding in it's
tag:

onclick="javascript:bSubmitted=true;"

However, adding this to a onCheckedChanged for a checkbox results in a
compilation error, saying ") expected".

Any more ideas?

Thanks
sorry, there was a Syntax error there.
Should have been:

document.getElementById('cb').checked

"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123839782.734420.108040@.f14g2000cwb.googlegr oups.com...
> Thanks, tried that but no luck. It stops the script from working for
> all controls on the page!? Think it errored, so it could have been the
> way i added it. Here's what I had:
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> if(!Document.GetElementById('addNewSurgeonChkBx'). Checked)
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> Here's the full original code, if that might give anymore ideas:
> // Warns user before page unload
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> var bSubmitted=false;
> function isDirty(oForm)
> {
> if(bSubmitted) return false;
> var iNumElems = oForm.elements.length;
> for (var i=0;i<iNumElems;i++)
> {
> var oElem = oForm.elements[i];
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> {
> if (oElem.value != oElem.defaultValue) return true;
> }
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
> {
> if (oElem.checked != oElem.defaultChecked) return true;
> }
> else if ("SELECT" == oElem.tagName)
> {
> var oOptions = oElem.options;
> var iNumOpts = oOptions.length;
> for (var j=0;j<iNumOpts;j++)
> {
> var oOpt = oOptions[j];
> if (oOpt.selected != oOpt.defaultSelected) return true;
> }
> }
> }
> return false;
> }
> It can be disadbled easily with the submit button by adding in it's
> tag:
> onclick="javascript:bSubmitted=true;"
> However, adding this to a onCheckedChanged for a checkbox results in a
> compilation error, saying ") expected".
> Any more ideas?
> Thanks
Thank you very much Grant. Thats almost made it work.

It now behaves correctly when the checkbox changes from false to true.
However, the message still appears when it changes from true to false.
I would like to stop this too.

I tried changing the .checked to .checkedchanged but that makes the
message box appear when the checkbox if changing from true to false and
from false to true.

Any ideas?

Thanks again

Set javascript value OnCheckedChanged

Hi,
I have a AutoPostBack checkbox and need to set a value bSubmitted =
true when the checkbox is checked in order to prevent a warning message
appearing notifying the user they are navigating away from the page.
I have been trying to add the following in the <script> section of the
<HEAD> section:
addNewSurgeonChkBx.Attributes.Add("onclick","Javascript:bSubmitted=true;");
But it does not seem to work, I still get the error message.
I have also tried to put it on the onLoad section of the C# CodeBehind,
here though it surpresses the error message for all controls, not just
the checkbox.
Any ideas of how to fix this?
Thanks.How about letting the JavaScript that pops up the notification check if the
checkbox is checked.
So where is says:
Confirm('Are you sure you want to navigate away from this page');
change that too
if(!Document.GetElementById('addNewSurgeonChkBx').Checked)
Confirm('Are you sure you want to navigate away from this page');
Is that what you looking for?
"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123775711.123436.307480@.g43g2000cwa.googlegroups.com...
> Hi,
> I have a AutoPostBack checkbox and need to set a value bSubmitted =
> true when the checkbox is checked in order to prevent a warning message
> appearing notifying the user they are navigating away from the page.
> I have been trying to add the following in the <script> section of the
> <HEAD> section:
> addNewSurgeonChkBx.Attributes.Add("onclick","java script:bSubmitted=true;")
;
> But it does not seem to work, I still get the error message.
> I have also tried to put it on the onLoad section of the C# CodeBehind,
> here though it surpresses the error message for all controls, not just
> the checkbox.
> Any ideas of how to fix this?
> Thanks.
>
Thanks, tried that but no luck. It stops the script from working for
all controls on the page!? Think it errored, so it could have been the
way i added it. Here's what I had:
function checkFormStatus(oForm)
{
if(isDirty(oForm))
if(!Document.GetElementById('addNewSurgeonChkBx').Checked)
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}
Here's the full original code, if that might give anymore ideas:
// Warns user before page unload
function checkFormStatus(oForm)
{
if(isDirty(oForm))
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}
var bSubmitted=false;
function isDirty(oForm)
{
if(bSubmitted) return false;
var iNumElems = oForm.elements.length;
for (var i=0;i<iNumElems;i++)
{
var oElem = oForm.elements[i];
if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
{
if (oElem.value != oElem.defaultValue) return true;
}
else if ("checkbox" == oElem.type || "radio" == oElem.type)
{
if (oElem.checked != oElem.defaultChecked) return true;
}
else if ("SELECT" == oElem.tagName)
{
var oOptions = oElem.options;
var iNumOpts = oOptions.length;
for (var j=0;j<iNumOpts;j++)
{
var oOpt = oOptions[j];
if (oOpt.selected != oOpt.defaultSelected) return true;
}
}
}
return false;
}
It can be dibled easily with the submit button by adding in it's
tag:
onclick="java script:bSubmitted=true;"
However, adding this to a onCheckedChanged for a checkbox results in a
compilation error, saying ") expected".
Any more ideas?
Thanks
sorry, there was a Syntax error there.
Should have been:
document.getElementById('cb').checked
"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123839782.734420.108040@.f14g2000cwb.googlegroups.com...
> Thanks, tried that but no luck. It stops the script from working for
> all controls on the page!? Think it errored, so it could have been the
> way i added it. Here's what I had:
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> if(!Document.GetElementById('addNewSurgeonChkBx').Checked)
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> Here's the full original code, if that might give anymore ideas:
> // Warns user before page unload
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> var bSubmitted=false;
> function isDirty(oForm)
> {
> if(bSubmitted) return false;
> var iNumElems = oForm.elements.length;
> for (var i=0;i<iNumElems;i++)
> {
> var oElem = oForm.elements[i];
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> {
> if (oElem.value != oElem.defaultValue) return true;
> }
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
> {
> if (oElem.checked != oElem.defaultChecked) return true;
> }
> else if ("SELECT" == oElem.tagName)
> {
> var oOptions = oElem.options;
> var iNumOpts = oOptions.length;
> for (var j=0;j<iNumOpts;j++)
> {
> var oOpt = oOptions[j];
> if (oOpt.selected != oOpt.defaultSelected) return true;
> }
> }
> }
> return false;
> }
> It can be dibled easily with the submit button by adding in it's
> tag:
> onclick="java script:bSubmitted=true;"
> However, adding this to a onCheckedChanged for a checkbox results in a
> compilation error, saying ") expected".
> Any more ideas?
> Thanks
>
Thank you very much Grant. Thats almost made it work.
It now behaves correctly when the checkbox changes from false to true.
However, the message still appears when it changes from true to false.
I would like to stop this too.
I tried changing the .checked to .checkedchanged but that makes the
message box appear when the checkbox if changing from true to false and
from false to true.
Any ideas?
Thanks again