Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"
This demo describes how to implement multiple delete in GridView using CheckBox control and display a confirmation message upon deletion.
Assuming that we have this GridView column mark up below
<Columns>
   <asp:TemplateField>
   <HeaderTemplate>
      <asp:Button ID="ButtonDelete" runat="server" Text="Delete" />
   </HeaderTemplate>
   <ItemTemplate>
      <asp:CheckBox ID="CheckBox1" runat="server" />
   </ItemTemplate>
   </asp:TemplateField>
   <asp:BoundField DataField="CustomerID" HeaderText="ID" ReadOnly="True" />
   <asp:BoundField DataField="CompanyName" HeaderText="Company"/>
   <asp:BoundField DataField="ContactName" HeaderText="Name"/>
   <asp:BoundField DataField="ContactTitle" HeaderText="Title" />
   <asp:BoundField DataField="Address" HeaderText="Address"/>
   <asp:BoundField DataField="Country" HeaderText="Country"/>
</Columns> 
For binding your GridView with data I would suggest you to refer to my previous example about “Binding GridView with data from Database
Now let’s create our method for deleting. First we need to declare the following namespaces below in order for us to use the SqlClient libraries, StringBuilder and StringCollection class.
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Text;
Here’s the code block for deleting multiple records
#region Multiple Delete
private void DeleteRecords(StringCollection sc)
{
   SqlConnection conn = new SqlConnection(GetConnectionString());
   StringBuilder sb = new StringBuilder(string.Empty);
 
   foreach (string item in sc)
   {
     const string sqlStatement = "DELETE FROM Customers WHERE CustomerID";
     sb.AppendFormat("{0}='{1}'; ",sqlStatement, item);
   }
   try
   {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
    }
    catch (System.Data.SqlClient.SqlException ex)
    {
            string msg = "Deletion Error:";
            msg += ex.Message;
            throw new Exception(msg);
     }
     finally
     {
            conn.Close();
     }
}
#endregion
The DeleteRecords() method takes one parameter which is basically a string collections of ID to be deleted. The method basically iterates all the ID that was stored in the StringCollection object. Those values stored in the String collections will be formatted together with the value of sqlStatements string and creates a concatenated delete statements based from the number of ID’s to be deleted. These concatenated values are then stored in the StringBuilder object and pass it in the SqlCommand as a parameter.
I used this approach so that we can execute multiple deletes at once and this way we only need to hit the database once.
Now let’s call DeleteRecords() method at the Delete Button_Click event of GridView that was located at the Header portion of the first column of the GridView. In order to generate the click event automatically you follow these few steps below:
1.       Switch to Design View in the Visual Studio Designer
2.       Right Click on the GridView and Select Edit Template -- > Column[0]
3.       Then the GridView will switch to edit mode
4.       Find the Delete Button in the Template and Double Click on the button to generate the event for you
5.       Then write the codes there for calling the Delete method and so on
6.       To switch back to default mode in GridView then just right click on the GridView and Select End Template Editing
7.       Then you are done
Here’s the code block for the Delete Button_Click event below
protected void ButtonDelete_Click(object sender, EventArgs e)
{
 StringCollection sc = new StringCollection();
 string id = string.Empty;
 //loop the GridView Rows
 for (int i = 0; i < GridView1.Rows.Count; i++){
      CheckBox cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1"); //find the CheckBox
      if (cb != null)
      {
         if (cb.Checked)
          {
            id = GridView1.Rows[i].Cells[1].Text; // get the id of the field to be deleted
            sc.Add(id); // add the id to be deleted in the StringCollection
           }
      }
 }
 
 DeleteRecords(sc); // call method for delete and pass the StringCollection values
 BindGridView(); // Bind GridView to reflect changes made here
}
The code above basically loops through the GridView rows and search for the TextBox was checked using FindControl() method. When a CheckBox is checked it will then get the corresponding ID for that row and add it in the StringCollection object. After it loops through all the CheckBox that was checked then we call the DeleteRecords() method to perform the deletion.
Note: Don’t forget to Bind your GridView with data after you call the delete method to reflect the changes in the GridView.
Now let’s create a confirmation message when a user attempts to delete records. I would also suggest you to read my previous example about “Display Confirmation on GridView Deleting”.
Here’s the JavaScript function for the delete confirmation.
<head runat="server">
    <title>GridView Data Manipulation</title>
    <script type="text/javascript" language="javascript">
        function ConfirmOnDelete(item)
        {
          if (confirm("The following item(s) will be deleted: " + item + "Continue?")==true)
            return true;
          else
            return false;
        }
    </script>
</head>
 
Here’s the code behind for calling the JavaScript function at RowDataBound event of GridView
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
        if (e.Row.RowType == DataControlRowType.Header) //check for RowType
        {
        //access the LinkButton from the Header TemplateField using FindControl
            Button b = (Button)e.Row.FindControl("ButtonDelete"); 
        //attach the JavaScript function
            b.Attributes.Add("onclick", "return ConfirmOnDelete();"); 
        }
}
Here’s the output when you run the page and do multiple deletion:
Technorati Tags: ,,,
Posted on Sunday, February 22, 2009 2:01 AM ADO.NET , ASP.NET , C# , GridView | Back to top


Comments on this post: GridView Multiple Delete with CheckBox and Confirm

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Hi, I used your coding for deletion. The control passes over all the lines and it did not display any errors. But the datas are not deleting. Can you solve the problem.
Left by Karthick on Mar 03, 2009 9:08 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
I've used your example to help-me create my own page that update records based on wich ones have been selected. Works perfectelly!
Thank you very much!
Left by Seidinger on Mar 10, 2009 3:20 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Helpful tutorial.
Thank in advance!
Left by Nimol on Mar 26, 2009 8:48 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
it was a nice one
Left by govind on Apr 01, 2009 5:49 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Thankz a lot , BOSS
Left by Abul Hasan on Apr 12, 2009 3:51 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
thanks.. i wnt to very simple coding
Left by Victor on Apr 16, 2009 3:20 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
thanks.. i want to very simple coding
Left by Victor on Apr 16, 2009 3:21 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
so good
Left by yothin on Jun 11, 2009 8:46 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Hi Vinz,

its very nice code and it helped me a lot....when i did the same as u said i my code was working fine. but when i tried to implement javascript to display a confirm box before deleting i m geting an error saying object reference is not set to instance of an object. when i debug the code to see where it is giving me error, i found out that before binding the data to gridview its going to RowDataBound event of the gridview and its throwing an exception saying object reference is not set to instance of an object. so what could be the reason for this error i m not able to figure it out. so kindly tell me a solution for this.
Left by JAY on Jun 15, 2009 9:53 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
compile time error..'System.EventArgs' does not contain a definition for 'Row'.. please help.. thanks in advance
Left by azar on Jun 30, 2009 12:29 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Hi,

If duplicate CustomerId is entered will it delete both the record or will it delete only the selected row.

Thank you
Left by Zeko on Jul 30, 2009 12:11 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Thank you very much for this article
Left by sam on Aug 27, 2009 10:08 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
could you send me the whole source & the file to my email!!
thx man!!! btw great info and damn u are expert in this!!!
Left by LoxZ on Sep 22, 2009 6:56 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
btw ur code did not validate the user!!
for example wad if the user nvr checked the checkbox!!!
but the javascript still come out????
Left by LoxZ on Sep 22, 2009 8:46 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Hi,
Your code is helpfull to me. And I want to ask how to check if have any checkbox is checked before show Message box confirm. How to do?

Thanks a lot
Left by Hoang Le on Nov 15, 2009 4:50 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Hi Vinz,

I have a problem.....

After clicking the Delete button the data is not getting deleted....
I have debugged the code and the control is simply not passing over the
"DeleteRecords" method.... can u help me....
Left by nikhil on Apr 02, 2010 2:27 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
When i click delete button without selecting any checkbox, java script runs and ask for confirmation. can anyone tell how to check first whether checkbox or checkboxes in grid is selected or not. if not it will ask to select a checkbox first.
Left by maverick on Apr 10, 2010 4:09 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Its very nice
Left by Munna on May 21, 2010 8:12 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
'System.EventArgs' does not contain a definition for 'Row.


protected void grdProduct_SelectedIndexChanged(object sender, EventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header) //check for RowType
{
Button b = (Button)e.Row.FindControl("ButtonDelete"); //access the LinkButton from the Header TemplateField using FindControl
b.Attributes.Add("onclick", "return ConfirmOnDelete();"); //attach the JavaScript function
}

}
Left by sanjay on Aug 05, 2010 3:25 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
thanks vinz for your support..........

now i am geeting new error....

Object reference not set to an instance of an object

Line 651: {
Line 652: CheckBox CheckBox1 = (CheckBox)row.FindControl("cbRows");
Line 653: if (CheckBox1.Checked)
Line 654: {
Line 655: int Rid = Convert.ToInt32(grdProduct.DataKeys[row.RowIndex].Value);

i am geeting error 653 line.......

Left by sanjay on Aug 05, 2010 4:32 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Lots of Thank for Code
Left by Jayesh on Aug 17, 2010 3:24 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
i cnt delete multiple records with ths code...pls help..gives me error
Left by akshaya on Sep 06, 2010 1:57 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Add Multiple Checkbox Selection to the above code. Then it will be the complete code. Thanks
Left by sunil jain on Sep 10, 2010 3:44 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
One shortcoming of this code is that if no selection is made, then it will throw exception. Plz add coding for the same
Left by Seo Services India on Sep 10, 2010 3:48 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Great resource , i loved the tutorial.
Left by Amalia on Dec 02, 2010 5:56 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
HELLO I AM WORKING ON MY GRADUATION PROJECT
IF CAN U PUT UR PROJECT IN ASPX CS FILES !
PLLZ
Left by HAZIM on Dec 18, 2010 1:24 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Just found this when searching. Thanks
Left by sim only deals on Dec 18, 2010 5:41 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
great tutorial for ADO.NET,ASP.NET,C#, GridView thanks for sharing....
Left by quick weight loss on Feb 03, 2011 7:11 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
May you give this code in VB.net
Left by scraps para orkut on Feb 06, 2011 3:15 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
can u help me on my project ...i want ur help.......
Left by Latest Mobile phone on Feb 10, 2011 6:36 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
hi... i like your project........and i am happy for choosing this ....thanks a lot dued....
Left by Pressure cooker on Feb 13, 2011 11:13 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
I shared this with this with my friend he also likes the blog
Left by IT consulting on Feb 15, 2011 5:38 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Just want to say thank you. I was feeling very good while reading that post.
Left by outlook pst repair on Feb 15, 2011 5:44 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Very good post with informative information. I really appreciate the fact that you approach these topics from a stand point of knowledge and information. This is the first time, I visited at your site and became your fan. You are bookmarked. Please keep on posting.
Left by SEO Outsourcing on Feb 15, 2011 7:15 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
it was very detailed guide for the topic, i gland you shared your experience
Left by htc wildfire deals on Feb 18, 2011 4:45 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
nice posting and people like’s your article because they feel good and awesome article you post thats why they post a comment and also me like your article keep it up.
Left by Nikon 7510 Travelite Binoculars on Feb 20, 2011 8:40 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
It is really hard to think in depth about this subject. I appreciate your efforts about this article. I have heard much about this country and the particular class in the country but never got a chance to get a deep idea about its economical and social structure. I read the whole article and found it impressive and appreciable. I was not much even aware with the concept of mine workers in Bolivia. I am thankful for such wonderful information on the subject
Left by Wireless Security Camera on Feb 27, 2011 2:29 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work.
Left by internet marketing and advertisi on Feb 27, 2011 3:09 PM

# flower
Requesting Gravatar...
This is a great blog with excellent posts and links.
Thanks for sharing.
Left by send mothers day flowers Spain on Mar 09, 2011 6:18 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Really interesting post. I enjoyed reading it. Will return again soon.
Left by Hire PHP Developer on Mar 22, 2011 1:29 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Tiananmen Square and more recently in Tibet, the Chinese have no freedom of expression themselves. What bothers me more is the image of "everything is big in China and we welcome the world" when in fact the reality is much different.
Left by Reviews on Apr 14, 2011 3:17 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Nice info..very useful post. Thanks for sharing!
Left by Mobile Phones on Apr 28, 2011 1:46 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
ExecuteNonQuery: CommandText property has not been initialized... I am getting this error please help
Left by kavita on May 01, 2011 6:10 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
YA NIKHIL IS RIGHT................Delete Button is not working
Left by Shalini on May 01, 2011 6:11 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
@Shalini,

I presume the Delete Button is now firing at all.. If so then have you followed the steps in generating the Click event handler for the Button. Your Button should have this mark up:

<asp:Button ID="ButtonDelete" runat="server" Text="Delete" OnClick="ButtonDelete_Click" />
Left by Vinz on May 02, 2011 3:56 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
This is a great suggestion. Many people ran into this problem without solution. learning tracks takes a little difficult at first, but if they persist and learn from examples, it is easy to find master. It is much like fixing a broken appliance.
Left by Repair PST on May 14, 2011 4:05 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
This will be a very big imagination that you are furnishing and you hand it away for free. I savour seeing websites that begin to see the value of furnishing a prime resource for free. I truly enjoyed reading your Wiley Post. Thanks!
Left by Cell Phone Spy on May 17, 2011 8:57 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
I came to your article from another article and am really interested in this learning about this.Thanks for sharing.
Left by 31 day fat loss cure on Jun 08, 2011 6:29 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
I would like to thank you for the efforts you have made in writing this article and I am hoping the same best work from you in the future as well.
Left by convert psd to html on Jun 09, 2011 3:11 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Fine information, many thanks to the author. It is puzzling to me now, but in general, the usefulness and significance is overwhelming. Very much thanks again and good luck!
Left by Botox Perth on Jun 15, 2011 9:12 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Thanks to spybubble reviews It's a new and great techonology.
It is really help me to know more about my child when I'm absence to them.
Please take a look at the spybubble reviews for a new and innovative way to give

you some peace of mind.
Left by brian@spybubble reviews on Jun 16, 2011 2:45 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Really i appreciate the effort you made to share the knowledge.The topic here i found was really effective to the topic which i was researching for a long time..
Left by Druckvorstufe on Jun 20, 2011 8:52 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
This is a very informative article.I was looking for these things and here I found it.
Left by hugo boss perfume on Jun 28, 2011 12:55 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Yes, well written article. I could find out some useful information on your blog guys. This is really useful for everyone. I love this post. Thanks for sharing it.
Left by website designing companies on Jul 18, 2011 4:27 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
This is a great suggestion. Many people ran into this problem without solution. learning tracks takes a little difficult at first, but if they persist and learn from examples, it is easy to find master. It is much like fixing a broken appliance.
Left by subrata Roy on Aug 12, 2011 7:11 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
very useful information
Left by hotfile downloads on Aug 26, 2011 6:31 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
A good solution here guys.
Left by Homes for Sale on Aug 26, 2011 7:56 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
it is agreat article i really liked it
Left by buy viagra online on Aug 31, 2011 4:38 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
how to delete multiple rows in gridview with checkbox choice & with confirmation using asp.net



this code give a mistake & i cannot find the Exception:-

the exception isFrown | :-( Object reference not set to an instance of an object.)
Left by jogos de motos on Sep 02, 2011 3:06 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
here is my class .
how am i going to pair these codes with my class
?
pleasepleasepleaseplease help

///////////////////////////////
public class DataAccess
{


SqlConnection connection=new SqlConnection();
string connectionstring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Administrator\Documents\Visual Studio 2008\WebSites\NEWhoneyBee\App_Data\Admin-Login.mdf;Integrated Security=True;User Instance=True";
SqlCommand command=new SqlCommand();


public DataAccess()
{

connection.ConnectionString = connectionstring;
command.Connection=connection;

}

public bool DoCommand(string query,SqlParameter [] sqlparams )//insert delete update/// ///////////parameters///////////
{
try
{
connection.Open();
command.CommandText = query;
command.Parameters.AddRange(sqlparams);
command.ExecuteNonQuery();
connection.Close();
return true;

}
catch
{
return false;
}

}



public bool DoCommand(string query)//insert delete update
{
try
{
connection.Open();
command.CommandText = query;
command.ExecuteNonQuery();
connection.Close();
return true;

}
catch
{
return false;
}

}


public DataTable select(string query, SqlParameter[] sqlparams)
{
try
{
command.CommandText = query;
command.Parameters.AddRange(sqlparams);
SqlDataAdapter adaptor = new SqlDataAdapter(command);
DataTable table = new DataTable();
adaptor.Fill(table);
return table;


}
catch
{
return null;
}

//
// TODO: Add constructor logic here
//
} ///////////parameters///////////

public DataTable select(string query )
{
try
{
command.CommandText = query;
SqlDataAdapter adaptor = new SqlDataAdapter(command);
DataTable table = new DataTable();
adaptor.Fill(table);
return table;


}
catch
{
return null;
}

//
// TODO: Add constructor logic here
//
}

public object select()
{
throw new NotImplementedException();
}
Left by ramin on Sep 07, 2011 12:00 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
I like you discussion very great topic.Interesting post and thanks for sharing. Some things in here I have not thought about before.Thanks for making such a cool post which is really very well written.will be referring a lot of friends about this.
Left by ads for free on Sep 09, 2011 9:26 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Really appreciate this website. It’s hard to sort the good from the bad sometimes,
but I think it just awesome!
Left by medihoney ointment on Sep 09, 2011 1:49 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
string connectionstring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Administrator\Documents\Visual Studio 2008\WebSites\NEWhoneyBee\App_Data\Admin-Login.mdf;Integrated Security=True;User Instance=True";
Left by propecia online on Sep 23, 2011 8:20 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
its good
Left by karthik on Oct 12, 2011 8:12 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
i have got this message in confirm box "undefined continue" and when i click ok button get this error screen

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Left by Najeeb on Oct 25, 2011 2:49 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
hi ,
very nice article i tried
but i am getting this error
"CommandText property has not been initialized "
can any one help on this
i tried both ways but no solvation

try
{
cn.Open();
SqlCommand cm = new SqlCommand();
cm.CommandType = CommandType.Text;
cm.CommandText = sb.ToString();
cm.Connection = cn;
cm.ExecuteNonQuery();

}

as well
try

{

conn.Open();

SqlCommand cmd = new SqlCommand(sb.ToString(), conn);

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

}
Left by murali on Oct 28, 2011 7:20 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
hai .
very nice article
works very well
thanks
Left by janardhan on Nov 05, 2011 7:50 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
string connectionstring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Administrator\Documents\Visual Studio 2008\WebSites\NEWhoneyBee\App_Data\Admin-Login.mdf;Integrated Security=True;User Instance=True";
Left by Cialis Without Prescription on Nov 08, 2011 5:25 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Your code can only take in one value from the GridView and pushes it into the SQL query right? E.g. It can only take in ID. What should I do for e.g. I have multiple same IDs, and I want to match each ID with the next column, Company? I would need a sql query which DELETE where ID like *** and Company like ***. How should I do it? Thank you
Left by Rui Hao on Nov 18, 2011 2:09 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Shingley Beach offers a large variety of affordable Airlie Beach Accommodation overlooking the Abel Point Marina and beautiful Whitsunday islands. If you are looking for a Airlie beach accommodation at an affordable price then go through www.shingleybeachresort.com.
Left by Airlie beach accommodation on Nov 18, 2011 5:14 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Binding GridView with data from Database , is good one for users on website for coding data . its a very good blog please do continue posting

thanks
Left by nuvodevtech on Dec 01, 2011 12:56 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
This is such a Great resource that you are providing and you give it away for free. It gives in depth information.

Thanks for this valuable information.
Left by web design bangalore on Dec 12, 2011 5:43 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Great article!
Left by valtrex online on Dec 17, 2011 6:15 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
how could i use stored procedure instead SQL statement ?
Left by swaiss on Dec 18, 2011 6:31 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Thank you so much! Have a nice day!
Left by hiibonjourVietnam on Dec 19, 2011 12:28 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
thanks a lot...It worked perfectly...:)
Left by Anvita on Dec 27, 2011 12:58 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
All the contents you mentioned in post are too good and can be very useful. This one is great and is really a good post. I think it will help me a lot in the related stuff and is very much useful for me. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.
Left by Cost of tattoo removal Brisbane on Dec 27, 2011 1:37 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
very nice artical thanks for such a good information
Left by songs on Dec 30, 2011 3:03 AM

# GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
It's very nice article
works very well
thanks
Left by Sarfraz Khan on Jan 09, 2012 5:52 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
It's very nice article But code error:"ExecuteNonQuery: CommandText property has not been initialized"
and i'm help is:
id=GridView1.DataKeys[i].Value.ToString();
Left by kennha811 on Jan 09, 2012 11:47 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
I am getting this error to, pls help !

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Left by Abdurrahman on Jan 12, 2012 4:27 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Coding shared here is very helpful.Thanks for contributing your important time to post such an interesting & useful collection.It would be knowledgeable & resources are always of great need to everyone. Please keep continue sharing.
Left by vending companies on Jan 23, 2012 8:42 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts. Thanks
Left by fotografo matrimonio on Jan 28, 2012 1:24 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Glad to visit this professional blog... I would love to learn more and more about technical and programming related things.. Great work!
Left by domain registration and hosting on Feb 02, 2012 7:02 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
give me insider information on what hiring managers are looking for in a chemist
Left by fitness articles on Apr 27, 2012 8:44 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
pls some one help me out.command text has nnot been intialised.
Left by anusha.s.c on Apr 28, 2012 2:47 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
command text property has not been intialised...........pls hellp me out pls pls pls pls
Left by anusha on Apr 28, 2012 3:13 PM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
All the capacity you mentioned in column are too acceptable and can be actual useful. This one is abundant and is absolutely a acceptable post. I anticipate it will advice me a lot in the accompanying being and is actual abundant advantageous for me. I will accumulate it in mind, acknowledgment for administration the advice accumulate updating, searching advanced for added posts.
Left by Mensagens Para Celular on May 10, 2012 11:55 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Left by jogos de motos on Jun 26, 2012 7:05 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
nate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Left by jogos de motos on Jun 26, 2012 7:16 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Thank you for all the clarifications. I always wondered just how to do such a thing. Now I know, and it makes me more optimistic.
Left by Laptop Specifications on Jul 16, 2012 2:52 AM

# re: GridView Multiple Delete with CheckBox and Confirm
Requesting Gravatar...
Great information. I have always wondered how to do such a thing, and now I know. Thanks for the detailed instructions. This is helpful in many parts of society, including the healthcare industry.
Left by Compression Pumps on Aug 07, 2012 1:39 AM

# mobile price in Pakistan
Requesting Gravatar...
I like you altercation actual abundant topic.Interesting column and acknowledgment for sharing. Some things in actuality I accept not anticipation about before.Thanks for authoritative such a air-conditioned column which is absolutely actual able-bodied written.will be apropos a lot of accompany about this.
Left by mobile phone on Aug 14, 2012 4:23 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net