Click here to Skip to main content
Click here to Skip to main content

Multi-select ASP.NET datagrid

By , 7 Mar 2004
 

Sample image

Introduction

ASP.NET datagrid is a very powerful and flexible control, however some features like multi-select is not natively available. This article shows how easily this functionality can be achieved with a few simple tricks.

Background

One of the projects I was working on had a User Inteface requirement for multi-selection of grid rows. User wanted Hotmail or Yahoo style multi-selection facility along with highlighting the selection (hard part).

Using the code

After testing and applying some javascript and grid related coding techinque, I came up with the following working solution.

  • Add Template column for CHECKBOXES for selection (Hotmail/Yahoo style)
  • Add client-side onclick() and javascript for checkboxes, to highlight and mark checked rows.
  • Add server side CheckedChanged() event for preserving highlights. [because everytime on postback datagrid resets colors for the selection]
<Columns>
 <asp:TemplateColumn>
  <HeaderTemplate>
   <asp:CheckBox id="chkAll" 
      onclick="javascript:SelectAllCheckboxes(this);" runat="server" 
    AutoPostBack="false" ToolTip="Select/Deselect All" />
  </HeaderTemplate>
  <ItemTemplate> 
    <asp:CheckBox id="chkSelect" onclick="javascript:HighlightRow(this);"
        runat="server"OnCheckedChanged= "grdEmployees_CheckedChanged" 
        AutoPostBack="false" />
  </ItemTemplate> 
 </asp:TemplateColumn> 
</Columns>

SelectAllCheckBoxes()

This function is used to have Hotmail style selection, it iterate through every check box on the form and then selects/deselects the checkboxes.

HighlightRow()

The only challenge left was to highlight and un-highlight the rows on selection and deselection. For which, I used HighlightRow() function, please note one very important thing when using <asp:CheckBox> control. It surrounds <SPAN> tags around CHECKBOX and therfore in javascript you have to get the children of the <SPAN> tag.

    //-------------------------------------------------------------
    // Select all the checkboxes (Hotmail style)
    //-------------------------------------------------------------
    function SelectAllCheckboxes(spanChk){
    
    // Added as ASPX uses SPAN for checkbox 
    var oItem = spanChk.children;
    var theBox=oItem.item(0)
    xState=theBox.checked;    

        elm=theBox.form.elements;
        for(i=0;i<elm.length;i++)
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
            {
            //elm[i].click();
            if(elm[i].checked!=xState)
            elm[i].click();
            //elm[i].checked=xState;
            }
    }

    //-------------------------------------------------------------
    //----Select highlish rows when the checkboxes are selected
    //
    // Note: The colors are hardcoded, however you can use 
    //       RegisterClientScript blocks methods to use Grid's
    //       ItemTemplates and SelectTemplates colors.
    //         for ex: grdEmployees.ItemStyle.BackColor OR
    //                 grdEmployees.SelectedItemStyle.BackColor
    //-------------------------------------------------------------
    function HighlightRow(chkB)    {
    var oItem = chkB.children;
    xState=oItem.item(0).checked;    
    if(xState)
        {chkB.parentElement.parentElement.style.backgroundColor='lightcoral';
           // grdEmployees.SelectedItemStyle.BackColor
         chkB.parentElement.parentElement.style.color='white'; 
           // grdEmployees.SelectedItemStyle.ForeColor
        }else 
        {chkB.parentElement.parentElement.style.backgroundColor='white'; 
             //grdEmployees.ItemStyle.BackColor
         chkB.parentElement.parentElement.style.color='black'; 
             //grdEmployees.ItemStyle.ForeColor
        }
    }
    // -->

This was the client side story. So far so good. One may argue why not use the plain simple HTML checkbox control? The answer is ASP.NET server control has a viewstate and therefore posting a page retains the rows selection.

Server Side

Now, On the server side we have to make sure the highlights are intact, because on every postback ASP.NET renders grid and loses the highlights. Following method is used for re-rendering the highlights.

Public Sub grdEmployees_CheckedChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs)
  Dim chkTemp As CheckBox = CType(sender, CheckBox)

  Dim dgi As DataGridItem 

  dgi = CType(chkTemp.Parent.Parent, DataGridItem)
  If (chkTemp.Checked) Then 

    dgi.BackColor = grdEmployees.SelectedItemStyle.BackColor 
    dgi.ForeColor = grdEmployees.SelectedItemStyle.ForeColor
  Else 

    dgi.BackColor = grdEmployees.ItemStyle.BackColor
    dgi.ForeColor = grdEmployees.ItemStyle.ForeColor 
  End If
End Sub

Getting your selection

Its easy! Iterate through the DataGridItems collection and grab the checkbox [for ex. DemoGridItem.Cells(0).Controls(1)]. And verify its CHECKED property. Oh, also you can use DataKeyField of the dataset to grab specific datarows. Check out the attached code and you will love to find out how easy it is to multi-select rows.

Conclusion

Follow the downloaded code, you can simply use any SQL database. This is my very first article, hope .NET lovers would like it. Feedback is welcome.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Prashant Nayak (.Net Lover)
Web Developer
United States United States
Member
Cranking code more than 12 years. Technical/Project lead/MCSD. Offered services to various industuries like S/W, Telecom, Publishing, Insurance etc.
 
When not on computer, I play/swim/read with my kids and help my better half (of course my lovely wife) to clean house. Solving challenging S/W problems is my passion. Hate non-productive meetings. Do lots of GOOGLE and Eat/Drink/Sleep around MSDN.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5membermanoj kumar choubey7 Feb '12 - 19:30 
Nice
GeneralMy vote of 5memberMember 782175621 Apr '11 - 10:23 
Thank you so much for the article, using the corrections i found in the chain of comments the article helped me a lot and saved tones of time!
GeneralMy vote of 1memberbadri vishal23 Nov '10 - 19:18 
javascript code to highlight row is not working
GeneralMy vote of 1memberDima Pasko27 Aug '09 - 11:49 
It's not working
GeneralMy vote of 1memberJitesh Sachdeva12 Jan '09 - 17:04 
code is very old and not working on vs2008
GeneralMultiSelect via Client-SidememberTodd Lucas1 Sep '06 - 12:31 
Check out this link: http://demo.c-cubed.net/C3WebControlsDemo/C3DataGrid_MultiSelect.aspx[^]
 
It's a DataGrid with client-side multiselect. All events happen on the client-side, with events firing upon postback to indicate which items(s) changed selection status. The multiselect indicator can appear in any column (or none), and can contain any specified HTML (not just an icon). No more clunky checkbox datagrid multiselects!
 
Thanks - TL
GeneralRe: MultiSelect via Client-SidememberPatrick Olurotimi Ige19 Sep '06 - 14:44 
Ver interesting job there Todd..
I went to the site and i loved the stuff.
Do you have the source code available?
Thanks
 
What you know today isn't enough for tommorow.

NewsMultiple Gridviews or Checkbox columnsmemberMcDude15 Jun '06 - 13:10 
I ran into a problem when I tried to use multiple gridviews on the same page.   When I checked the box on the top of one GridView, it checked all the boxes in all of them!   I fiddled around with it for way too long, until I came up with the following solution.
 
      //check all the checkboxes in the gridview to select all rows
      //06/15/2006 - Added indexOf stuff because multiple gridviews made all checkboxes checked
      function SelectAllCheckBoxes(theBox, gvSelected)
      {
            var xState=theBox.checked;
            var elm=theBox.form.elements;
            var strElmID;
 
            for(i=0;i<elm.length;i++)
            {
                  strElmID = elm[i].id;
                  if(elm[i].type=="checkbox" && strElmID!=theBox.id && strElmID.indexOf(gvSelected)!=-1 )
                  {
                        if(elm[i].checked!=xState)
                        {
                              elm[i].click();
                        }
                  }
            }
      }
 
Notice I am now searching for a string gvSelected in the id of the checkbox.   Since the .NET naming convention will name all of the checkboxes with concatenation and numbering, all we have to do is specify a different id for each checkbox column, and search for that as we cursor through all the elements on the page.
 
The following is the code for the first gridview and the beginning of the second:
 
<asp:GridView ID="gvDefHrs" runat="server" AutoGenerateColumns="false" DataKeyNames="emp_def_earn_uuid"
      DataSourceID="SqlDataSource1" OnRowCommand="gvDefHrs_RowCommand" OnRowDataBound="gvDefHrs_RowDataBound">
      <Columns>
            <asp:TemplateField>
                  <HeaderTemplate>
                        <input id="chkAllDefHrs" runat="server" onclick="SelectAllCheckBoxes(this,'chkSelectDefHrs');"
                              type="checkbox" />
                  </HeaderTemplate>
                  <ItemTemplate>
                        <asp:CheckBox ID="chkSelectDefHrs" runat="server" />
                  </ItemTemplate>
            </asp:TemplateField>
            <asp:ButtonField ButtonType="Button" CommandName="EditDefHrs" Text="edit" />
            <asp:BoundField DataField="earn_hrs" HeaderText="Hours" SortExpression="earn_hrs" />
            <asp:BoundField DataField="emp_def_earn_uuid" HeaderText="UUID" SortExpression="emp_def_earn_uuid"
                  Visible="false" />
      </Columns>
</asp:GridView>
 

<asp:GridView ID="gvDefDollars" runat="server" AutoGenerateColumns="false" DataKeyNames="emp_def_earn_uuid"
      DataSourceID="SqlDataSource2" OnRowCommand="gvDefDollars_RowCommand" OnRowDataBound="gvDefDollars_RowDataBound">
      <Columns>
            <asp:TemplateField>
                  <HeaderTemplate>
                        <input id="chkAllDefDollars" runat="server" onclick="SelectAllCheckBoxes(this,'chkSelectDefDollars');"
                              type="checkbox" />
                  </HeaderTemplate>
                  <ItemTemplate>
                        <asp:CheckBox ID="chkSelectDefDollars" runat="server" />

 
McDude lives
GeneralRe: Multiple Gridviews or Checkbox columnsmemberCode Buster10 Aug '06 - 19:36 
McDude, you are a legend, may you live longer. Thanks Mate.
 
The way I google it.

Generalunselect check box based on others ckbxmemberJamshidi3 Mar '06 - 12:09 
Hi,
is there a way to for example unselect checkbox#2 when #3 is check and the other way around?
 
also, how to get the ID/Name of the checkbox in question?
 
Thankx

GeneralCommand button in data GridmemberS.Das2 Mar '06 - 20:28 
hi
 
i want to add command buttons in data grid and each button should have seprate
click event.
 
i just want whenever user will click on particular button a particular .aspx file get open.
 
thanks
GeneralJavascript FunctionsmemberShadi Rahmani4 Sep '05 - 21:40 
i have a problem with javascript function that the chkAll can't find it's children . what can i do ?
 
shadirahmani
 
-- modified at 6:55 Monday 5th September, 2005
GeneralRe: Javascript Functionsmemberenjoycrack5 Sep '05 - 0:12 
hi there,
 
u can view HTML source code of the web page to identify the children controls's id so that u can have solution accordingly
 
<< >>
AnswerRe: Javascript FunctionsmemberSasi Atia12 Feb '06 - 20:52 
Smile | :) Testing this code showed that I had to remove the refrence for any children as their were no <span> tags to itrate through simply update the javascript to the following:
//-------------------------------------------------------------
      // Select all the checkboxes (Hotmail style)
      //-------------------------------------------------------------
      function SelectAllCheckboxes(spanChk){
     
      // Added as ASPX uses SPAN for checkbox
      var oItem = spanChk;
      var theBox=oItem
      xState=theBox.checked;     
            elm=theBox.form.elements;
            for(i=0;i<elm.length;i++)
            if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
                  {
                  //elm[i].click();
                  if(elm[i].checked!=xState)
                  elm[i].click();
                  //elm[i].checked=xState;
                  }
      }
 
      //-------------------------------------------------------------
      //----Select highlish rows when the checkboxes are selected
      //
      // Note: The colors are hardcoded, however you can use
      //         RegisterClientScript blocks methods to use Grid's
      //         ItemTemplates and SelectTemplates colors.
      //            for ex: grdEmployees.ItemStyle.BackColor OR
      //                        grdEmployees.SelectedItemStyle.BackColor
      //-------------------------------------------------------------
             function HighlightRow(chkB)      {
                var oItem = chkB;
               var xState;
               xState=oItem.checked;
               if(xState)
                    {chkB.parentElement.style.backgroundColor='lightcoral';
                    chkB.parentElement.style.color='white';
                    }else
                    {chkB.parentElement.style.backgroundColor='white';
                    chkB.parentElement.style.color='black';
            }
      }
      // -->
 
Sasi Atia
GeneralRe: Javascript Functionsmemberhb3219 Mar '08 - 3:47 
great job, i was having the same issue with the children not recognized - this worked for me! thanks!
Generalc# versionmemberLoic Deniel23 Aug '05 - 22:16 
First of all, thanks for the code, it is very helpful
 
and for the those who are really lazy typing it Wink | ;) , here is the C# version of the server code:
 
public void grdEmployees_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox myCheckBox = (CheckBox)sender;
DataGridItem dgi;
 
dgi = (DataGridItem)myCheckBox.Parent.Parent;
 
if(myCheckBox.Checked)
{
dgi.BackColor = grdEmployees.SelectedItemStyle.BackColor;
dgi.ForeColor = grdEmployees.SelectedItemStyle.ForeColor;
}
else
{
dgi.BackColor = grdEmployees.ItemStyle.BackColor;
dgi.ForeColor = grdEmployees.ItemStyle.ForeColor;
}
}

GeneralRe: c# versionsussAnonymous26 Oct '05 - 8:04 
this server method(grdEmployees_CheckedChanged) will not run when I check/uncheck the boxes. The client script works perfectly. I have followed all instructions. Is there anything I left out? Anyone has any idea?
Questionhow to get cell Text when AutoGenerateColumns="false"memberhostlike4 Aug '05 - 19:57 
When I tried this sample code and change AutoGenerateColumns to false, and add custom column template to the datagrid, I cannot retrieve the cell text.
 
in smample code:
mySelection.AppendFormat("{0}
", DemoGridItem.Cells(1).Text)
 
when AutoGenerateColumns="false", the cell text is empty.
 
Please help. thanks.Sigh | :sigh:
 
IT makes life crazy!
GeneralModified client scriptmemberdpadevet21 Jul '05 - 3:26 
Try this one:
 
<script language="javascript">    
     function SelectAllCheckboxes(chkBox) {                   
          var chk=chkBox.checked;                        
          var boxes=document.getElementById('dgMain').getElementsByTagName("input")                   
 
          for (i=0;i<boxes.length;i++){
               if (boxes.item(i).type=='checkbox' & !(boxes.item(i)==chkBox)) {
                              boxes.item(i).checked=!chk;
                              boxes.item(i).click();
                         }
          }
     }
                             
     function HighlightRow(chkB)     {                   
          if (chkB.checked) {
               chkB.parentNode.parentNode.style.backgroundColor='black';
               chkB.parentNode.parentNode.parentNode.style.backgroundColor='white';
          } else {                        
               chkB.parentNode.parentNode.style.backgroundColor='white';
               chkB.parentNode.parentNode.parentNode.style.backgroundColor='black';
          }                   
     }    
</script>
GeneralRe: Modified client scriptmemberhtb huang19 Mar '07 - 12:32 
This one works for me, Thank you.
GeneralButton instead of CheckBoxmemberJureshka7 Jul '05 - 4:53 
if I use a button instead of a checkbox,
the onclick event in javascript give me and errorCool | :cool:
 
Jureshka
GeneralMozilla Firefox Browersmembertaithien22 Jun '05 - 23:55 
Great!
But can you tell me how to run this demo by Firefox browers? The java script code is not working!
Thanks!
 
Hoac Tai Thien
GeneralRe: Mozilla Firefox Browersmemberwildwildwolf20 Jul '05 - 9:50 
In Mozilla FireFox when I test it, the parentNode.parentNode only comes up to the cell level instead of row like in IE given if you use TemplateColumn. Just put a browser sniffer in and giving FireFox with parentNode.parentNode.parentNode and it will work just fine.
 
Have fun
Generalscript correctionmember][Turpa28 Mar '05 - 0:51 
When I've changed JavaScript It worked. See below.
 
function SelectAllCheckboxes( chkAll )
{
xState=chkAll.checked;
elm=chkAll.form.elements;

for(i=0;i
General,memberHui Yee4 Mar '05 - 16:34 
Hi
Generalhope!membertengtium3 Mar '05 - 2:56 
a mjor problem with dotnetjunkies version, is that selection does not persits.. meaning even u select something and you implement a paging in datagrid or sorting .. the selection does not persist..
 
can somebody have a good link or idea about this
GeneralRe: hope!memberzedaspintas5 Apr '05 - 23:35 
i'm writing an article on how to do that, but the data is stored in a database...soon i'll post it here
 
the article covers:
- binding data into a datagrid from a database
- checking/unckecking the row(s) when the page loads and in every postback
 

GeneralDude, this is been done before and better on DotNetJunkies. Be original!sussAnonymous9 Jan '05 - 6:13 

Nice try, but be original and don't rehash.
GeneralRe: Dude, this is been done before and better on DotNetJunkies. Be original!sussAnonymous10 Jan '05 - 3:22 
Hi,
I am surprised but thanks for your comments.
 
I know you are not going to believe. In fact, when I needed such a solution couldn't find it on internet and then I thought of trying on my own.
 
Anyways, if you could please mention the link would be helpful to verify and improve my solution.
 
Smile | :)
GeneralRe: Dude, this is been done before and better on DotNetJunkies. Be original!sussAnonymous31 Aug '05 - 2:30 
Have some class ..."Dude" and don't be so judgmental.
GeneralRe: Dude, this is been done before and better on DotNetJunkies. Be original!memberChetan Sharma14 Aug '06 - 11:51 
"Dude" Appreciate what Prashant has done, rather that you yourself being judgemental and "Dude" attitude. Take Chill! Pill!
 
Poke tongue | ;-P
 
- web
GeneralRe: Dude, this is been done before and better on DotNetJunkies. Be original!memberMikel Dublin24 Sep '07 - 0:16 
Really nice contribution. What about the link?
GeneralnothingsussAnonymous10 Dec '04 - 4:16 
aaaaaaaaaaaaaaaaaaMad | :mad: Mad | :mad: Roll eyes | :rolleyes: Mad | :mad:
GeneralDatagrid Check all function problemsussshiva kumar5828 Nov '04 - 22:27 
I have used the "check all" function for the datagrid.
Locally when checking the header template check box all item template check boxes are checking
 
But after uploading them to site it's not working?
 
Pls help me.
GeneralDatagrid Check all function problemmembershiva kumar5828 Nov '04 - 22:27 
I have used the "check all" function for the datagrid.
Locally when checking the header template check box all item template check boxes are checking
 
But after uploading them to site it's not working?
 
Pls help me.
GeneralDoesn't workmembercah_batak11 Nov '04 - 21:38 
it's really a great article dan i had used it in my application. but there is one thing that doesn't work.
after checked the CheckAll and i checked the chkSelect, the CheckAll still checked.
howto fix it
regards
GeneralTHX for sharingmemberesman21 Nov '04 - 13:50 
I was looking for this feature and you have saved me time.
My datagrid is linked to a SQL database and holds user settings.
 
Does anyone know if its possible to call a client side jscript function from the server side vb code or vis versa.
Wink | ;)
THX in advance.
 
Keep up the good work.
GeneralSome little BugfixingssussGrischa Brockhaus25 Oct '04 - 6:21 
First: You should use parentNode instead of parentElement, because this is understood by Mozilla and IE. I changed the hardcoded colors to className settings, so color configuration can be done in an external CSS file, that's nicer. Smile | :)
 
And all the objects given to te JS Functions are the CheckBoxes itself (you used "this" as parameter), so you don't have to find the checkBox.
 
Here comes my modified code:
 
//-------------------------------------------------------------
// Select all the checkboxes (Hotmail style)
//-------------------------------------------------------------
function SelectAllCheckboxes(theBox){
xState=theBox.checked;
 
elm=theBox.form.elements;
for(i=0;i
GeneralRe: Some little Bugfixingsmembershakespeare218919 Dec '04 - 19:15 
Grischa,
 
This was great!!!
I've been spending literally, 4 hours looking for the solution to this bug..(I happend just to be 4months old in VB.NET)
 
can u pls tell me what was the original code's intention and how you found out that the "this" object was the box itself?
 

Generalform.element problemmemberMrKhalid11 Sep '04 - 9:39 
Hi Prashant
 
Nice job!!
 
I am trying to implement your code into my own datagrid coding.
 
It works OK when I clicked to select a single row, but not when I clicked to uncheck the same row.
 
I got an error when I tried to select the whole rows in a single page.
The error is: form.element is null or not an object!!
 

What's wrong? I have named my form as yours which is Form1 and I'm using Framework 1.0
 
Thanks
 
ILoveMicrosoft!!
GeneralData Gridmemberyathiraju_n9 Sep '04 - 19:39 
how i can change the position of the Data grid columns on asp.net page
 
Have Look at this
GeneralRe: Data Gridmemberrizingstar7730 Nov '05 - 11:24 
In VS Design Mode u can go into DataGrid properties-->property builder then click on columns tab then u can move cols up and down by clicking on each column then click arrow,
 
OR
 
In HTML mode simply cut n paste where u want each column to appear
GeneralYea, it works...i did itmemberK.Nagalinga Reddy29 Aug '04 - 5:38 
Folks,
 
This article,"Multi-select ASP.NET datagrid" by Prashanth is excellent. It tried and found really works. The only variation we have to follow is that, replace the line of code:
var theBox=oItem.item(0);
with,
var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
 
Thatz all. It works now.
 
Prashanth has given the code as per the .NET Framework 1.0. So if you are using .NET Framework 1.0, then it works fine. But if you are using the .NET Framework 1.1 or higher version, the follow the above variation. I have had to beat my head with some R&D with Prashanth's code and got the solution. Finally i found the code working with the above said change.
 
3cheers to Prashanth for providing this valuable source.
 
Thanks to all.
 
Thanks & Regards,
K.Nagalinga Reddy
AZTEC Software Inc.
Koramangala,Bangalore.
GeneralRe: Yea, it works...i did itsussAnonymous6 May '05 - 9:35 
Thanks for the help its working now Big Grin | :-D
GeneralJust Great but I Would Like one Select..memberManolo Herrera18 Aug '04 - 7:51 
Is amazing to see javascript all it can do and your article is just a great solution for my actual developing job. I would like use a checkbox more like select button so I just need one checkbox selected. But I new in javascript and I don´t know how I can unselect the selected checkbox before selecting another checkbox. I try combaning your allchecked function but Something I mess and It doesn´t work!.
 
So please help me and Thanks in advance!
 
Manolo Herrera
GeneralCheckedChanged event does not firememberBharat Gadhia18 Aug '04 - 6:49 
Hi,
I have a datagrid with checkboxes in itemtemplate of datagrid as follows:
 
                                        <asp:TemplateColumn>
                                             <HeaderTemplate>
                                                  <asp:Label id="lblchkAll" runat="server" ToolTip="Select each row">SelectTo</asp:Label>
                                             </HeaderTemplate>
                                             <ItemTemplate>
                                                  <asp:CheckBox id="chkSelect" runat="server" onclick="javascript:check(this);" Text="Remove" AutoPostBack="false"
                                                       ToolTip="Select/Deselect each row" OnCheckedChanged ="CheckedChanged"></asp:CheckBox>
                                             </ItemTemplate>
                                        </asp:TemplateColumn>
 
and I have also wired checkbox event in itemcreated event of page as follows:
 
public void ItemCreated(Object sender, DataGridItemEventArgs e)
{
// Get the newly created item
 
ListItemType itemType = e.Item.ItemType;
if((itemType == ListItemType.Item)||(itemType ==ListItemType.AlternatingItem) ||(itemType ==ListItemType.EditItem))
{
TableCell QueryTableCell2 = new TableCell();                        
QueryTableCell = e.Item.Cells[0];
                    CheckBox cBox = (CheckBox)QueryTableCell.Controls[1];
cBox.CheckedChanged += new System.EventHandler(CheckedChanged);
                   
}                                            
and have impleneted this event as follows:
 
public void CheckedChanged(Object sender,System.EventArgs e)
{
     CheckBox chkTemp = (CheckBox)(sender);
     DataGridItem dgi;
     dgi = (DataGridItem)(chkTemp.Parent.Parent);
     if(chkTemp.Checked)
     {
     chkTemp.Checked = true;
     }
     else
     {
     chkTemp.Checked = false;
     }         
}
 
also javascript in HTML part of page loos simillar as follows:
          <script>function check(chkB)
          {
               var xState=chkB.checked;
    
               if(xState)
               {
                    chkB.Checked = true;
               }
               else
               {
                    chkB.Checked = false;
               }
          }
          </script>
 
Can you please suggest me where I may be missing something? Or why event is not firing?
 
Thank you so much for help.
Bharat.
GeneralRe: CheckedChanged event does not firememberwildwildwolf19 Jul '05 - 12:16 
I changed autopostback of the checkbox to true.
 
Whatever heh
GeneralLoad form with check boxes populatedsussAnonymous13 Aug '04 - 13:55 
Hi There,
 
I need to have a number (not all) of the check boxes check when the page loads. The user can then check new ones and un-check existing ones. I have everything worked out, except how can I make the check box for the row = true?
 
Any ideas
 
Thanks
 
Lee
GeneralRe: Load form with check boxes populatedmemberPrashant Nayak (.Net Lover)16 Aug '04 - 3:15 
Lee,
Just set checkedproperty of the checkbox to TRUEin page_load()event.
 
Ex:
checkbox1.checked=TRUE
 

 
MCSD (.NET Lover)
GeneralSome column not changememberQ_Quek8 Aug '04 - 18:52 
Dear Prashant,
 
I had success to highlight the row which is been clicked. However, It was hightlight the checkbox(column 0)only. Can you teach me how to highlight the others in same row?Confused | :confused:
 
I got a problemFrown | :( need to solve if you don't mind to share. I want to hide/visible a text box if the checkbox is checked. Thank you.
 
Calvin;)
 
****

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 8 Mar 2004
Article Copyright 2003 by Prashant Nayak (.Net Lover)
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid