|
 |
|
|
 |
|
|
I like to load the project , build it and be able to modify it
I get an error about wanting to install web dev components. Anyway,
what type of project is it? Asp.net web app or asp.net control.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
You can use <asp:TemplateColumn> tag column under section in the datagrid
<asp:TemplateColumn>
<asp:CheckBox id="chkSelect" GroupName="grpSelect" runat="server">
Jegan
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi, if we wanna add also one more checkbox to select all or unselect all, what should we do? I think this will help us writing such communication based pages like mails, i had this problem on my page, if u are interested i will be glad thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ok.... I just went ahead and modified some code for everyone so that they can easily add a checkbox in the header which allows select/deselect all. This is server-side so if you have alot of traffic i would advise not to use this; instead use javascript. Whats nice about this code is that it is just a modification in the class and no where else.
using System; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace DataGridControls { /// /// CheckBoxColumn Derives from DataGrid Column /// public class CheckBoxColumn : DataGridColumn { public CheckBoxColumn(): base() { } public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { //let the base class initialize the cell base.InitializeCell(cell, columnIndex, itemType); //add checkbox to header if(itemType == ListItemType.Header) { CheckBox headerCheckBox = new CheckBox(); headerCheckBox.ID = "chkAll"; headerCheckBox.CheckedChanged += new EventHandler(this.headerCheckBox_CheckedChanged); headerCheckBox.AutoPostBack = true; cell.Controls.Add(headerCheckBox); }
//now we add a checkbox to the rest of the cells if( itemType == ListItemType.EditItem || itemType == ListItemType.Item || itemType == ListItemType.AlternatingItem || itemType == ListItemType.SelectedItem) {
HtmlInputCheckBox checkbox = new HtmlInputCheckBox(); checkbox.Name = "checkboxCol"; checkbox.ID = "checkboxCol"; //assign an ID that we can use to find the control later cell.Controls.Add(checkbox); }
}
private void headerCheckBox_CheckedChanged(object sender, EventArgs e) { foreach (DataGridItem item in this.Owner.Items) { //iterate each DataGridItem and find our checkbox HtmlInputCheckBox chkBox = (HtmlInputCheckBox) item.FindControl("checkboxCol"); //now set that checkboxCol value = to selected if(chkBox.Checked == false) chkBox.Checked = true; else chkBox.Checked = false; } } public Int32[] SelectedIndexes { get { ArrayList selectedIndexList = new ArrayList(); //iterate each DataGridItem and find our checkbox foreach( DataGridItem item in this.Owner.Items ) { HtmlInputCheckBox chkBox = (HtmlInputCheckBox) item.FindControl("checkboxCol"); //If it's selected then add it to our ArrayList if ( chkBox != null && chkBox.Checked ) { selectedIndexList.Add( item.ItemIndex ); } } return (Int32[])selectedIndexList.ToArray(typeof( System.Int32 ) ); } } public object[] SelectedDataKeys { get { //Just iterate each of the selectedindexes and //match it up to the datakey field ArrayList dataKeyList = new ArrayList(); //make sure the datakeys have some values if(this.Owner.DataKeys.Count > 0) { foreach( Int32 selectedIndex in SelectedIndexes ) { object DataKey = (this.Owner.DataKeys[selectedIndex].ToString()); dataKeyList.Add(DataKey); } } return (object[])dataKeyList.ToArray(typeof( object ) ); } } } }
Sully
|
| Sign In·View Thread·PermaLink | 4.50/5 (2 votes) |
|
|
|
 |
|
|
If you check or uncheck some boxes then do a select/deselect all, it simply flips the state of the checkboxes, that is not what I needed so... I modified this function in order to set all check boxes to the header box state (all checked or all unchecked).
private void headerCheckBox_CheckedChanged(object sender, EventArgs e) { //grab the sender state here CheckBox headerBox; headerBox = (CheckBox) sender; bool l_bState = headerBox.Checked; foreach (DataGridItem item in this.Owner.Items) { //iterate each DataGridItem and find our checkbox HtmlInputCheckBox chkBox = (HtmlInputCheckBox) item.FindControl("checkboxCol"); //now set the checkbox to the sender state chkBox.Checked = l_bState; } }
//low
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
I think my problem is with the referencing. I'm not exactly sure where I'm supposed to place the class file. Should I start a new class library and place it in there?????
My assembly load trace
=== Pre-bind state information === LOG: DisplayName = DataGridCheckbox (Partial) LOG: Appbase = file:///c:/inetpub/wwwroot/donationnationCS LOG: Initial PrivatePath = bin Calling assembly : (Unknown). ===
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Post-policy reference: DataGridCheckbox LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/donationnationcs/baaf210b/9fa24547/DataGridCheckbox.DLL. LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/donationnationcs/baaf210b/9fa24547/DataGridCheckbox/DataGridCheckbox.DLL. LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/donationnationCS/bin/DataGridCheckbox.DLL. LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/donationnationCS/bin/DataGridCheckbox/DataGridCheckbox.DLL. LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/donationnationcs/baaf210b/9fa24547/DataGridCheckbox.EXE. LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/donationnationcs/baaf210b/9fa24547/DataGridCheckbox/DataGridCheckbox.EXE. LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/donationnationCS/bin/DataGridCheckbox.EXE. LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/donationnationCS/bin/DataGridCheckbox/DataGridCheckbox.EXE.
Please help..... Thankyou
Sully
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi
this class support 2 CHECKBOXCOLUMN ?
I wanna know if someone have added 2 CHECKBOXCOLUMN in the same datagrid ?
i got this error
Multiple controls with the same ID 'checkboxCol' were found. FindControl requires that controls have unique IDs.
______________ Olog-hai Near to Mordor hugues_gauthier@hotmail.com
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Okay,
I add the project to my solution, create a reference to the dll, and add the @ Register directive at the top of my form. Runs great, and is so easy to use!
If I try to retreive the values as you have described I get a Data type undefined error. Why? I am using a code-behind. Is there something you need to do to make it work in a code-behind?
Thanks!
Dustin Boston
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello,
I used your code in order to add a checkbox column to my datagrid.
So I would like to put in the header a checkbox to select/Deselectall.
I know put the checkbox in the header but i don't know how i have to program .
Thank you for your help.
Fred.
|
| Sign In·View Thread·PermaLink | 1.67/5 (7 votes) |
|
|
|
 |
|
|
 |
|
|
i added the following inorder to set the inital values
in the webform.aspx added these lines
ArrayList selArray = new ArrayList(); foreach(DataRow dr in Ds.Tables[0].Rows) { selArray.Add(dr.ItemArray.GetValue(1)); }
second column in my datatable will have value "CHECK" or "UNCHECK" from my database.
in the web contorl i added one more method
public void setSelectedIndex(ArrayList selArray) { int indexchk = 0; foreach( DataGridItem item in this.Owner.Items ) { HtmlInputCheckBox chkBox = (HtmlInputCheckBox) item.FindControl("checkboxCol");
//If it's selected then add it to our ArrayList if ( chkBox != null && selArray[indexchk].Equals("CHECK") ) chkBox.Checked = true; else chkBox.Checked = false;
indexchk++; } }
And i am able to achieve the result. However I have little different problem now. ny dataset will vary on each post back. First time it checks accordingly but when i postback it doesn't change The checkbox values are not changing and the initial values are retained.
can somebody help on this.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I am able to get the correct values if i set the checkboxes disabled. But i dont want it that way. can any body help it.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
I don't know what this guy is talking about. As long as you set your references, it works just fine. Also, this guy has poor communication skills
SNook
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi,
Using your checkbox column object, is there a simple way to select or deselect all checkboxes in the column ?
Thanks,
Peter
|
| Sign In·View Thread·PermaLink | 2.83/5 (6 votes) |
|
|
|
 |
|
|
i have setted the DataKeyField of DataGrid on desin view,then,when i view a page on IE,a error message say 'SelectedIndexes is only read', ......
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
Yeah, I had that too. You have to go into the HTML and edit the checkbox attributes to remove it.
Snook
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |