validations for dropdownlist

Posted by Saritha.rajeshkumar under C# on 4/25/2011 | Points: 10 | Views : 1482 | Status : [Member] | Replies : 3
which type of validation should i use for dropdownlist.(i.e if user does not select it should show error message).




Responses

Posted by: Prabhakar on: 4/25/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Saritha.rajeshkumar

check in if condition Select Index property

if ( Dropdownlist.SelectedIndex = -1 )
{
}
else
{
}

Best Regard's
Prabhakar

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Laghaterohan on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
On the 0th index set --Select--- and put Required Field Validator and set its initial value to 0.

It will give error if the user does not select anything from the ddl.


Thanks!

Best Regards,
Rohan Laghate

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srinivas673 on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
//in Jquery
var IsRequired = "";
var IsInvalid = "";
IsRequired = 'The following fields are mandatory:<br />';
IsInvalid = 'The following are invalid:<br/>';

$('a[id$=lnkbtnupdate]').click(function () {

//Validate Type
if ($('select[id$=ddltype]').val() == "0") {
alertmessage($('select[id$=ddltype]'), $("#imgedittype"));
}
else {
removealertmessage($('select[id$=ddltype]'), $("#imgedittype"));
}

//Validaing Description
if ($('input[id$=txtDescription]').val() == "") {
str += "- Description <br/>";
alertmessage($('input[id$=txtDescription]'), $("#imgeditdesc"));
}
else {
removealertmessage($('input[id$=txtDescription]'), $("#imgeditdesc"));
}

if (str != '' && strInvalid != '') {
$('div[id$=divError]').show();
$('div[id$=divError]').attr('class', 'error');
$('span[id$=lblErrorMsg]').html(IsRequired + str + '<br/>' + IsInvalid + strInvalid);
return false;
}
else if (str != '' && strInvalid == '') {
$('div[id$=divError]').show();
$('div[id$=divError]').attr('class', 'error');
$('span[id$=lblErrorMsg]').html(IsRequired + str);
return false;
}
else if (str == '' && strInvalid != '') {
$('div[id$=divError]').show();
$('div[id$=divError]').attr('class', 'error');
$('span[id$=lblErrorMsg]').html(IsInvalid + strInvalid);
return false;
}
else
return true;
});


Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response