Click here to Skip to main content
14,735,108 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
in My grid view, Each row has a Delete button (which Generate dynamic generate for No of Rows).

when i click delete button for delete this row then more then one row is delete by generating Loop type .

how can i disable it ,.....
Posted
Updated 14-Apr-14 21:51pm
v2
Comments
[no name] 14-Apr-14 6:34am
   
please give more information. What all events are you firing on gridview and all? If possible provide your code for reference.
mukesh mourya 14-Apr-14 6:50am
   
//here i m bind grid view from database in window form


private void Subjectseup()
{
gvsubjectsetup.DataSource = null;
try
{
string querystring = "SELECT * FROM dbo.Subjects";
DataTable datatable = Class1.Datatablebind(querystring);

gvsubjectsetup.AutoGenerateColumns = false;

//Set Columns Count
gvsubjectsetup.ColumnCount = 8;

//Add Columns
gvsubjectsetup.Columns[0].Name = "Subjectid";
gvsubjectsetup.Columns[0].HeaderText = "Subject Id";
gvsubjectsetup.Columns[0].DataPropertyName = "Subject_id";

gvsubjectsetup.Columns[1].HeaderText = "Subject Name";
gvsubjectsetup.Columns[1].Name = "Subject";
gvsubjectsetup.Columns[1].DataPropertyName = "Subject Name";

gvsubjectsetup.Columns[2].HeaderText = "Allow Class";
gvsubjectsetup.Columns[2].Name = "AllowClass";
gvsubjectsetup.Columns[2].DataPropertyName = "Allow Class";

gvsubjectsetup.Columns[3].Name = "SubjectType";
gvsubjectsetup.Columns[3].HeaderText = "Subject Type";
gvsubjectsetup.Columns[3].DataPropertyName = "Subject Type";

gvsubjectsetup.Columns[4].HeaderText = "Subject Valuation";
gvsubjectsetup.Columns[4].DataPropertyName = "Subject valuation";

gvsubjectsetup.Columns[5].HeaderText = "Create Date";
gvsubjectsetup.Columns[5].DataPropertyName = "Create date";

gvsubjectsetup.Columns[6].HeaderText = "Category";
gvsubjectsetup.Columns[6].DataPropertyName = "category";

// add a button column.
DataGridViewButtonColumn updatebutton = new DataGridViewButtonColumn();
// DataGridViewButtonColumn addsectionbutton = new DataGridViewButtonColumn();
DataGridViewButtonColumn deletbutton = new DataGridViewButtonColumn();

updatebutton.HeaderText = "Update Classes";
updatebutton.Text = "Update";
updatebutton.Name = "btnUpdate";

// addsectionbutton.HeaderText = "Add Section";
// addsectionbutton.Text = "Add Section";
// addsectionbutton.Name = "btnaddsection";

deletbutton.HeaderText = "Delete Classes";
deletbutton.Text = "Delete";
deletbutton.Name = "btnDelete";

updatebutton.UseColumnTextForButtonValue = true;
deletbutton.UseColumnTextForButtonValue = true;
// addsectionbutton.UseColumnTextForButtonValue = true;

gvsubjectsetup.Columns.Add(updatebutton);
// gvsubjectsetup.Columns.Add(addsectionbutton);
gvsubjectsetup.Columns.Add(deletbutton);

// ADD click event on button

gvsubjectsetup.CellClick += new DataGridViewCellEventHandler(gvsubjectsetup_click);
// gvsubjectsetup.DataSource = datatable;
gvsubjectsetup.DataSource = new BindingSource(datatable, null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}








// here i m call this mathod on click "showdata " Button



void gvsubjectsetup_click(object sender, DataGridViewCellEventArgs e)
{
if ((e.RowIndex > 0) || (e.ColumnIndex == gvsubjectsetup.Columns["btnUpdate"].Index) || (e.ColumnIndex == gvsubjectsetup.Columns["btnDelete"].Index))
{
if (e.ColumnIndex == gvsubjectsetup.Columns["btnUpdate"].Index)
// MessageBox.Show("hi this is section"+ taskID);
{
int id ;
id = (Int32)gvsubjectsetup[0, e.RowIndex].Value;
string s =
mukesh mourya 14-Apr-14 7:18am
   
above Show My Code.... i have no idea what i do for it please any one help me ...its urgent
thatraja 16-Apr-14 5:47am
   
Post the code in your question using "Improve question" link(Yes, update your question)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900