Click here to Skip to main content
15,915,160 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Checkbox in a grid Pin
neerubee30-Dec-07 20:08
neerubee30-Dec-07 20:08 
GeneralRe: Checkbox in a grid Pin
Sun Rays30-Dec-07 20:43
Sun Rays30-Dec-07 20:43 
GeneralRe: Checkbox in a grid Pin
SreejithAchutan30-Dec-07 21:15
SreejithAchutan30-Dec-07 21:15 
GeneralRe: Checkbox in a grid Pin
Sun Rays30-Dec-07 21:39
Sun Rays30-Dec-07 21:39 
GeneralRe: Checkbox in a grid Pin
SreejithAchutan30-Dec-07 21:54
SreejithAchutan30-Dec-07 21:54 
GeneralRe: Checkbox in a grid Pin
Sun Rays30-Dec-07 22:01
Sun Rays30-Dec-07 22:01 
GeneralRe: Checkbox in a grid Pin
SreejithAchutan30-Dec-07 22:13
SreejithAchutan30-Dec-07 22:13 
GeneralRe: Checkbox in a grid Pin
rahul.net1130-Dec-07 21:47
rahul.net1130-Dec-07 21:47 
Hi This could help.
<br />
<br />
function select_deselectAll (chkVal, idVal)<br />
{<br />
  var frm = document.forms[0];<br />
   // Loop through all elements<br />
  for (i=0;i< frm.length; i++)<br />
  {<br />
    // Look for our Header Template's Checkbox<br />
      if (idVal.indexOf ('CheckAll') != -1)<br />
      {<br />
        // Check if main checkbox is checked, then select or deselect datagrid checkboxes<br />
if(chkVal == true)<br />
{<br />
 frm.elements[i].checked = true;<br />
}<br />
else<br />
{<br />
frm.elements[i].checked = false;<br />
}<br />
// Work here with the Item Template's multiple checkboxes<br />
        }<br />
      else if (idVal.indexOf ('DeleteThis') != -1)<br />
      {<br />
    // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox<br />
if (frm.elements[i].checked == false)<br />
{<br />
  frm.elements[1].checked = false;<br />
  //Uncheck main select all checkbox<br />
}<br />
       }<br />
 }<br />
}<br />
function confirmDelete (frm)<br />
{<br />
 // loop through all elements<br />
 for (i=0; i<frm.length; i++)<br="" mode="hold" /> {<br />
   // Look for our checkboxes only<br />
  if (frm.elements[i].name.indexOf("DeleteThis") !=-1)<br />
   {<br />
     // If any are checked then confirm alert, otherwise nothing happens<br />
     if(frm.elements[i].checked)<br />
     {<br />
      return confirm ('Are you sure you want to delete your selection(s)?')<br />
     }<br />
   }<br />
}<br />
}<br />
<br />
<br />
<asp:datagrid id="MyDataGrid" runat="server" width="700" backcolor="white" bordercolor="black"><br />
CellPadding="3" CellSpacing="0" Font-Size="9pt" AutoGenerateColumns="False" HeaderStyle-BackColor="darkred" HeaderStyle-ForeColor="white"><br />
< Columns><br />
< asp:TemplateColumn><br />
< HeaderTemplate><br />
< asp:CheckBox ID="CheckAll" OnCheckedChanged="javascript: return select_deselectAll (this.checked,this.id);" runat="server" /><br />
< font face="Webdings" color="white" size="4">< /font><br />
< /HeaderTemplate><br />
< ItemTemplate><br />
< asp:CheckBox ID="DeleteThis" OnCheckedChanged="javascript: return select_deselectAll (this.checked, this.id);" runat="server" /><br />
< /ItemTemplate><br />
< /asp:TemplateColumn><br />
< asp:TemplateColumn><br />
< HeaderTemplate><br />
ID<br />
< /HeaderTemplate><br />
< ItemTemplate><br />
< asp:Label ID="StoreID" Text='< %# DataBinder.Eval (Container.DataItem, "ID") %>' runat="server"/><br />
< /ItemTemplate><br />
< /asp:TemplateColumn><br />
< asp:BoundColumn HeaderText="Store" Datafield="Store" runat="server" /><br />
< asp:BoundColumn HeaderText="Address" Datafield="Address" runat="server" /><br />
< asp:BoundColumn HeaderText="City" Datafield="City" runat="server" /><br />
< asp:BoundColumn HeaderText="State" Datafield="State" runat="server" /><br />
< asp:BoundColumn HeaderText="Zip" Datafield="Zip" runat="server" /><br />
< /Columns><br />
< /ASP:DataGrid><br />
<br />
<br />
< asp:Button Text="Delete Items" OnClick="DeleteStore" ID="Confirm" runat="server" /><br />
< span id="OutputMsg" runat="server" /><br />
<br />
public void DeleteStore (Object sender, EventArgs e)<br />
{<br />
string dgIDs = "";<br />
bool BxsChkd = false;<br />
foreach (DataGridItem i in MyDataGrid.Items)<br />
{<br />
CheckBox deleteChkBxItem = (CheckBox) i.FindControl ("DeleteThis");<br />
if (deleteChkBxItem.Checked)<br />
{<br />
BxsChkd = true;<br />
// Concatenate DataGrid item with comma for SQL Delete<br />
dgIDs += ((Label) i.FindControl ("StoreID")).Text.ToString() + ",";<br />
}<br />
}<br />
// Set up SQL Delete statement, using LastIndexOf to remove tail comma from string.<br />
string deleteSQL = "DELETE from Stores WHERE stor_id IN (" + dgIDs.Substring (0, dgIDs.LastIndexOf (",")) + ")";<br />
if (BxsChkd == true)<br />
{<br />
// Execute SQL Query only if checkboxes are checked, otherwise error occurs with initial null string<br />
try<br />
{<br />
SqlHelper.ExecuteNonQuery (objConnect, CommandType.Text, deleteSQL);<br />
}<br />
catch (SqlException err)<br />
{<br />
//Exception Catching code as usual displaying message<br />
}<br />
//Refresh data<br />
BindData();<br />
}<br />
}</asp:datagrid>


People Laugh on me Because i am
Different but i Laugh on them
Because they all are same.

GeneralWorking with dynamically created controls Pin
Anuradha61230-Dec-07 18:55
Anuradha61230-Dec-07 18:55 
GeneralRe: Working with dynamically created controls Pin
Paul Conrad30-Dec-07 18:58
professionalPaul Conrad30-Dec-07 18:58 
GeneralRe: Working with dynamically created controls Pin
Anuradha61230-Dec-07 19:05
Anuradha61230-Dec-07 19:05 
GeneralRe: Working with dynamically created controls Pin
Paul Conrad30-Dec-07 19:08
professionalPaul Conrad30-Dec-07 19:08 
GeneralRe: Working with dynamically created controls Pin
N a v a n e e t h30-Dec-07 19:10
N a v a n e e t h30-Dec-07 19:10 
GeneralRe: Working with dynamically created controls Pin
Paul Conrad30-Dec-07 19:13
professionalPaul Conrad30-Dec-07 19:13 
GeneralRe: Working with dynamically created controls Pin
N a v a n e e t h30-Dec-07 19:26
N a v a n e e t h30-Dec-07 19:26 
GeneralRe: Working with dynamically created controls Pin
Paul Conrad30-Dec-07 19:31
professionalPaul Conrad30-Dec-07 19:31 
GeneralRe: Working with dynamically created controls Pin
Anuradha61230-Dec-07 19:11
Anuradha61230-Dec-07 19:11 
GeneralRe: Working with dynamically created controls Pin
N a v a n e e t h30-Dec-07 19:09
N a v a n e e t h30-Dec-07 19:09 
GeneralRe: Working with dynamically created controls Pin
N a v a n e e t h30-Dec-07 19:07
N a v a n e e t h30-Dec-07 19:07 
GeneralRe: Working with dynamically created controls Pin
Anuradha61230-Dec-07 19:16
Anuradha61230-Dec-07 19:16 
GeneralRe: Working with dynamically created controls Pin
N a v a n e e t h30-Dec-07 19:41
N a v a n e e t h30-Dec-07 19:41 
GeneralRe: Working with dynamically created controls Pin
rahul.net1130-Dec-07 19:40
rahul.net1130-Dec-07 19:40 
GeneralRe: Working with dynamically created controls Pin
Paul Conrad31-Dec-07 5:56
professionalPaul Conrad31-Dec-07 5:56 
GeneralRe: Working with dynamically created controls Pin
Imran Khan Pathan30-Dec-07 19:52
Imran Khan Pathan30-Dec-07 19:52 
GeneralRe: Working with dynamically created controls Pin
Paul Conrad31-Dec-07 5:56
professionalPaul Conrad31-Dec-07 5:56 

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.