Click here to Skip to main content
15,889,527 members
Home / Discussions / C#
   

C#

 
GeneralRe: Installer custom action Pin
JacquesDP30-Jul-06 17:51
JacquesDP30-Jul-06 17:51 
GeneralRe: Installer custom action Pin
mav.northwind31-Jul-06 20:44
mav.northwind31-Jul-06 20:44 
QuestionTo reduce the length(items) of dropdownlist Pin
Ravi Shankar4327-Jul-06 20:15
Ravi Shankar4327-Jul-06 20:15 
QuestionReporting Service Print Problem Pin
leo_asp27-Jul-06 19:21
leo_asp27-Jul-06 19:21 
QuestionSetup Deployment of C# windows appl with Framework and database. Pin
Mithun Acharya27-Jul-06 18:46
Mithun Acharya27-Jul-06 18:46 
AnswerRe: Setup Deployment of C# windows appl with Framework and database. Pin
Stefan Troschuetz27-Jul-06 21:29
Stefan Troschuetz27-Jul-06 21:29 
QuestionDataGrid Pin
bakm0427-Jul-06 12:35
bakm0427-Jul-06 12:35 
AnswerRe: DataGrid Pin
Vipin Venugopal27-Jul-06 17:57
Vipin Venugopal27-Jul-06 17:57 
This code will help u to get the whole row of the grid selected when u click a check box in the corresponding rows of the grid. Hope this solves ur issue.


using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace solCommon.Web.UI.DataGrid
{
///
/// CheckBoxColumn Derives from DataGrid Column
///

public class DGCheckBoxColumn : DataGridColumn
{
public DGCheckBoxColumn(): base()
{
}

public override void InitializeCell(TableCell cell,
int columnIndex, ListItemType itemType)
{
//let the base class initialize the cell
base.InitializeCell(cell, columnIndex, itemType);

if( itemType == ListItemType.EditItem ||
itemType == ListItemType.Item ||
itemType == ListItemType.AlternatingItem ||
itemType == ListItemType.SelectedItem ||
itemType == ListItemType.Header)
{

CheckBox checkbox = new CheckBox();
//assign an ID that we can use to find the control later
//we don't want to add a normal checkbox to the header.
checkbox.ID = (itemType==ListItemType.Header)? "checkboxHead": "checkboxCol";

cell.Controls.Add(checkbox);
}
}
public Int32[] SelectedIndexes
{
get
{
ArrayList selectedIndexList = new ArrayList();
//iterate each DataGridItem and find our checkbox
foreach( DataGridItem item in this.Owner.Items )
{
CheckBox chkBox =
(CheckBox) 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 ) );
}

}

public static void RegisterClientCheckEvents(Page pg, string formID)
{
string strCol = GetCheckColScript();
string strHead = GetCheckHeadScript();

if(!pg.IsClientScriptBlockRegistered("clientScriptCheckAll"))
pg.RegisterClientScriptBlock("clientScriptCheckAll", strHead.Replace("[frmID]",formID));
if(!pg.IsClientScriptBlockRegistered("clientScriptCheckChanged"))
pg.RegisterClientScriptBlock("clientScriptCheckChanged", strCol.Replace("[frmID]",formID));

RegisterAttributes(pg);

}

private static void RegisterAttributes(Control ctrl)
{
foreach (Control wc in ctrl.Controls)
{
try
{
if ( wc.HasControls() )
RegisterAttributes(wc);

CheckBox chk = (CheckBox)wc;
if (chk != null && chk.ID == "checkboxCol")
{
chk.Attributes.Add("onclick","CheckChanged()");
}
else if ( chk != null && chk.ID == "checkboxHead")
{
chk.Attributes.Add("onclick","CheckAll(this)");
}
}
catch
{
}
}
}

private static string GetCheckColScript()
{
string strScript;
strScript= " ";
strScript+=" function CheckAll( checkAllBox )";
strScript+=" {";
strScript+=" var frm = document.[frmID];";
strScript+=" var ChkState=checkAllBox.checked;";
strScript+=" for(i=0;i< frm.length;i++)";
strScript+=" {";
strScript+=" e=frm.elements[i];";
strScript+=" if(e.type=='checkbox' && e.name.indexOf('checkboxCol') != -1)";
strScript+=" e.checked= ChkState ;";
strScript+=" }";
strScript+=" }";
strScript+=" ";

return strScript;
}

private static string GetCheckHeadScript()
{
string strScript="";
strScript= "";
strScript+="function CheckChanged()";
strScript+="{";
strScript+=" var frm = document.[frmID];";
strScript+=" var boolAllChecked;";
strScript+=" boolAllChecked=true;";
strScript+=" for(i=0;i< frm.length;i++)";
strScript+=" {";
strScript+=" e=frm.elements[i];";
strScript+=" if ( e.type=='checkbox' && e.name.indexOf('checkboxCol') != -1 )";
strScript+=" if(e.checked== false)";
strScript+=" {";
strScript+=" boolAllChecked=false;";
strScript+=" break;";
strScript+=" }";
strScript+=" }";
strScript+=" for(i=0;i< frm.length;i++)";
strScript+=" {";
strScript+=" e=frm.elements[i];";
strScript+=" if ( e.type=='checkbox' && e.name.indexOf('checkboxHead') != -1 )";
strScript+=" {";
strScript+=" if( boolAllChecked==false)";
strScript+=" e.checked= false ;";
strScript+=" else";
strScript+=" e.checked= true;";
strScript+=" break;";
strScript+=" }";
strScript+=" }";
strScript+=" }";
strScript+=" ";

return strScript;
}
}
}



Vipin
QuestionResetting Screen Scroll Position on a Winform Pin
tjschilling27-Jul-06 10:09
tjschilling27-Jul-06 10:09 
QuestionInitializing dictionary with a struct? help pls Pin
honeyman_can27-Jul-06 9:24
honeyman_can27-Jul-06 9:24 
AnswerRe: Initializing dictionary with a struct? help pls Pin
Judah Gabriel Himango27-Jul-06 9:39
sponsorJudah Gabriel Himango27-Jul-06 9:39 
Generalthanks dude! Pin
honeyman_can27-Jul-06 9:44
honeyman_can27-Jul-06 9:44 
QuestionVerifying User input Pin
TheJudeDude27-Jul-06 9:09
TheJudeDude27-Jul-06 9:09 
AnswerRe: Verifying User input Pin
Not Active27-Jul-06 9:15
mentorNot Active27-Jul-06 9:15 
GeneralRe: Verifying User input Pin
TheJudeDude31-Jul-06 10:44
TheJudeDude31-Jul-06 10:44 
GeneralRe: Verifying User input Pin
Not Active31-Jul-06 12:10
mentorNot Active31-Jul-06 12:10 
AnswerRe: Verifying User input Pin
Legolas.Bilbao27-Jul-06 9:16
Legolas.Bilbao27-Jul-06 9:16 
GeneralRe: Verifying User input Pin
TheJudeDude27-Jul-06 9:21
TheJudeDude27-Jul-06 9:21 
GeneralRe: Verifying User input Pin
Judah Gabriel Himango27-Jul-06 9:44
sponsorJudah Gabriel Himango27-Jul-06 9:44 
AnswerRe: Verifying User input Pin
Stefan Troschuetz27-Jul-06 9:19
Stefan Troschuetz27-Jul-06 9:19 
AnswerThe following is a joke Pin
Ennis Ray Lynch, Jr.27-Jul-06 9:30
Ennis Ray Lynch, Jr.27-Jul-06 9:30 
GeneralRe: The following is a joke Pin
Judah Gabriel Himango27-Jul-06 9:45
sponsorJudah Gabriel Himango27-Jul-06 9:45 
GeneralRe: The following is a joke Pin
User 665827-Jul-06 10:14
User 665827-Jul-06 10:14 
GeneralRe: The following is a joke Pin
Judah Gabriel Himango27-Jul-06 10:18
sponsorJudah Gabriel Himango27-Jul-06 10:18 
AnswerRe: Verifying User input Pin
Judah Gabriel Himango27-Jul-06 10:17
sponsorJudah Gabriel Himango27-Jul-06 10:17 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.