.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

CheckBoxes In Asp.net MVC

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Hi Guys,

I am new to asp.net mvc.. i have a question that how to deal with the checkboxes in the asp.net mvc and how to apply the validation on that ??? what i want is i have a checkbox against Email textbox and if that checkbox is selected than email must be entered..how do i do that ??

Hoping a reply as soon as possible..

Thanks a lot in advance..

View Complete Post

More Related Resource Links

Checkboxes from data table


I have a data table that contains some values for Certifications.  This table can be updated in a different part of my application.  On the web page I am currently working on, I would like to have check boxes appear for every value in the data table.  I have been struggling with this trying to use a For Each loop and I cannot get it to work for anything.  Any suggestions? 

I am using the following Razor syntax to obtain my data (I know this works because I can display it in a WebGrid):


var db = Database.Open("MyConn");

Select all checkboxes in gridview using Javascript


Hello members,


              I have used "Check box" inside the gridview...

              I need,

                           If i select the header check box , It should select all the checkbox inside the gridview...

              I have searched in google for this coding ...I got  lot of codes but couldn't get the correct code...

              I request anyone please provide me the correct code(using Javascript) thanks...

Checkboxes in Datagrid


This morning I posted a question w.r.t Radio Buttons, but the requirement changed so I'm posing a similar question.

I want to have a checkbox in a datagrid.

Suppose I click on one of the checkboxes and then realize i need to click on another, the screen has to automatically uncheck the previously clicked checkbox and then check the newly clicked checkbox.

In other words I need to clear previously checked checkboxes and check the recently clicked checkbox.

Also, I need to update a label in the page with a value associated with the row of the checked checkbox.

I should not be using a javascript to do this.

Any help in this regard would be highly appreciated.

Checkboxes in Datagrid

Hello Group, I have a question about dynamically generated checkboxes in a grid view. These checkboxes are checked depending on a value from the database. This is al working fine. I want to check or uncheck some checkboxes on different lines and when i push a button i want to receive the values of the checkboxes, but i can accomplish this.   Anyone who can help me? René

HELP - Problems with programatically adding checkboxes

Here is the setup. I programatically add a Canvas, a Grid, and within that grid are two columns of checkboxes. I have the Canvas there for querying purposes (makes it easier). The problem is that after the method executes that does all this and the form is displayed the canvas is visible, but the checkboxes aren't. When I set a breakpoint at the end of the method and check to make sure that all the Children are where they are supposed to be, they are all in their correct places. For what it's worth here is the code for the method. I cannot, for the life of me, figure out why they are not being rendered. They are there there when breaking down the items children for each of the controls. private void AddItemsToQuestion(Canvas pQuestionCanvas, XElement pQuestion) { List<XElement> pItems = (from c in pQuestion.Elements("Item") select c).ToList(); if (pItems.Count <= 0) return; int iNumberOfRows = (int)Math.Ceiling((double)pItems.Count / 2); //get the question canvas name Dictionary<string, object> pQuestionTag = ((Dictionary<string, object>)pQuestionCanvas.Tag); string sQuestionName = pQuestionTag["Name"].ToString(); Canvas pItemsCanvas = new Canvas(); pItemsCanvas.Width = pQuestionCanvas.Width; pItemsCanvas.Height = iNumberOfRows * 25; Thickness pThick

HDI : Enable and Disable checkboxes inside of DataGrid Template

I am again trying stuff that is a challenge.What i need to do is to enable and disable checkboxes in the gridI enable/disable them when i bind in grdDocApprovals_ItemDataBoundusing the following syntax( (CheckBox)e.Item.FindControl("chkReceived" )).Enabled = true;( (CheckBox)e.Item.FindControl("chkApproved" )).Enabled = false;That works wonderful. It disables the checkbox and i can not tick it.Now the problem comes in when i Tick the chkReceived box then i executemy javascript that finds the chkApproved box and is suppose to enable it.I noticed that in the HTML code during runtime there is a span and a td thatsurrounds the chkApproved. The <span>have a disabled = 'disabled' tag.and no matter what i do i can not get the chkApproved to be enabled. <span disabled="disabled"><input id="_ctl0_ContentMain_grdDocApprovals__ctl3_chkApproved" type="checkbox" name="_ctl0:ContentMain:grdDocApprovals:_ctl3:chkApproved" disabled="disabled" onclick="javascript:return response(this);" /></span>what can i do to get it active?

How to order checked checkboxes

hi everyone i have an infopath 2007 form and i have couple checkboxes in a mutiple selection list box. I wanna know is there a way while I'm saving the form it just keeps the selected checkboxes or otherwise if it's too complicate is it a way to order them and have the checked on the top to retrieve them faster

validate both dropdown and listview checkboxes+Javascript

I have checkboxes in one column of  listview and outside the listview I have one  dropdown and one button.when I dont check any checkboxes in listview  fire a validation "Select any one checkbox" on button click.simirarly when I check Checkboxes in listview and I'm leaving to select dropdown fire a validation"Select any item in the dropdownlist" on button click.how to validate both controls(checkboxes in listview and dropdown) when those are not selecting. Many thanks in advance.

checkbox in listview layout template check select all checkboxes in listview itemtemplate

hi,how to do this when the checkbox in listview layout template check select all checkboxes in  listview itemtemplate.I dont give 'Eval 'field to checkbox present in itemtemplate.pls reply me.Many thanks in advance.

List and adding checkboxes

Hello, I am using a TabControl on my Windows Form with several tabs. I have got checkboxes on each tab. When a user clicks on the button I will add selected checkboxes into a list control (List<CheckBoxes>). The problem is that the checkboxes are added into the list in very unusable order (e.g. the last (the lowest) checkbox on the tab is added before the first checkbox on the tab. How can I control the order the checkboxes are added into the list? Sorry for my English. Thanks.  

How to read checkbox values from programmatically created checkboxes?


I have a form that does a loop to create checkboxes.  Here is the code in the loop:

cbxDrives.Top = TopPosition;
cbxDrives.Left = LeftPosition;
cbxDrives.Text = d.Name; 
CheckBox cbxDrives = new CheckBox();this.Controls.Add(cbxDrives);

This creates multiple check boxes on the form, and this works fine.

However, in the code behind for my button that the user clicks to execute the form, I cannot figure how how to read the values for the checkboxes.  I've tried:

foreach (CheckBox cbxDrive in cbxDrives)


DataType for DropDownLists, ListBox, CheckBoxes and RadioButtons



When using a DropDownList, ListBox, CheckBoxes, RadioButtons what data type do you suggest to hold the values?

Usually the values are 1, 2, 3, etc. It makes more sense to me and usually these are the id's of the items.

I tend to use the following:

1) When only ONE option can be selected I amke the property of type INT? (Nullable int).

    This is for when no item is selected it makes more sense to me to check if it's null then 0. 

    And in most validation frameworks there is a null validator.

2) If MANY options can be selected then I use INT[].

    Then I can check for null or count the selections.

What do you think?



check/clear checkboxes


I'm trying to make a custom control that checks or clears all checkboxes on a page simultaneously when a designated checkbox is checked or cleared. I have this (non-working) code so far:

    Public Shared Sub CheckUncheck(ByVal container As Control, ByVal blnChecked As Boolean)
        Dim intCount As Integer = 0, intTotal As Integer = container.Controls(0).Controls.Count
        Do While intCount < intTotal
            If container.Controls(0).Controls(intCount).GetType = GetType(CheckBox) Then
                Dim chk As CheckBox = CType(container.Controls(0).Controls(i), CheckBox)
                chk.Checked = blnChecked
            End If
            intCount += 1
    End Sub

The line that's giving me trouble is the one starting with "If container.Controls(0)"... Bad syntax that gives me this message: Operator '=' is not defined for types System.Type and System.Type. What I'm trying to do, of course, is test to see if the control is a checkbox; and if it is, either check or clear it depending on the value of blnChecked.

Select multiple checkboxes placed inside a combobox



I have just started working on WPF and I am fairly new to this technology. I need to add a excel filter like functionality for datagrid control. I have successfully added a combobox(with checkboxes inside) in the header of the datagrid. The datagrid needs to display "All" as first checkbox. If user checks this first checkbox all other checkboxes(inside same combo) need to be checked automatically. Following is my datatemplate for combo. I have placed in column header combo through codebehind.

<DataTemplate x:Key="comboTemplate">

   <ComboBox Name="cboTask" Loaded="cboTask_Loaded" Wid

How to import excel that has checkboxes.


I've got an excel file that has a number of regular cells and a number of checkboxes. I can access individual cells by using openrowset feature.

The problem is reading checkbox.value. 

I'd appreciate any help.


Custom Strong type HTML Helper for checkboxes?



MVC contains a strong typed HTML Helper (HTML.CehckBoxFor()) this takes a bool and returns a bool. To make the URL smaller I am thinking to change the bool values on the model object to byte or somthing like that so the url only contains &Parameter=1.

I have found this snippet :

public static string DatePickerFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,Expression<Func<TModel, TProperty>> expression)
  where TModel : class
    var inputName = ExpressionHelper.GetExpressionText(expression);
    return htmlHelper.DatePicker(inputName);

But I have no clue how to turn this in to a strong typed HTML Helper for checkbox that takes byte instead of bool. Its also important that the model object is set with byte instead of bool.

Any sugestions?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend