datagrid delete with 2 users

D

dmalhotr2001

Hi,

I have a datagrid hypothetically with this data:

id | text | link
-------------------------------
1 | first row | delete button
2 | second row | delete button

I have 2 users with 2 DIFFERENT browser instances.

I have a problem.

If user 1 deletes row with id 1, his screen refreshes and he gets:

id | text | link
-------------------------------
2 | second row | delete button


However now, user 2, still has the previous screen:

id | text | link
-------------------------------
1 | first row | delete button
2 | second row | delete button

User 2 tries to delete row 1 within a few seconds of user 1 deleting
row 1.

However when user 2 does this user 2 deletes row 2 and gets!

id | text | link
-------------------------------


To select the row to delete I do this:
string selectedRow = e.Item.Cells[0].Text;

However for user 2 it picks up the second row which is incorrect. How,
do I tell in .net to pick up the current row, so for each user they
pick up the current row. It looks like its posting back. Is there a
way to capture which button was clicked because onpostback I'm binding
the grid repeatedly. I want it not to bind the grid if delete is
pressed.

Thanks

:D
 
G

Guest

use this datagrid event to find which button was click.Info should be in
DataGridCommandEventArgs
DataGrid1_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
 
D

dmalhotr2001

I don't understand what you mean. I need to find out on POSTBACK.
Please provide a brief sample if possible.

Thanks in advance.

:D
 
G

Guest

Let me know if this helps.

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack )
{
//You need to retrieve the data and bind to the datagrid
BindDataGrid();
}
}
private void DataGrid1_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataRow dr = Ds.Tables[0].Rows.Find(e.Item.Cells[0].Text);
dr.Delete();
BindData();
}
private void BindDataGrid()
{
SqlConnection Conn = new SqlConnection("string connection");
SqlDataAdapter Da= new SqlDataAdapter("query", Conn);
Conn.Open();
DataSet Ds= new DataSet();
Da.Fill(Ds);
DataGrid1.DataSource = Ds;
DataGrid1.DataBind();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top