Hi all, could you please help me with my problem?
I have created DataGrid with Edit button and I want to have there also Delete button on each row.
But there should be some functionality like if user click on Delete, Delete link should change to two links "Yes" and "No". And than if user click Yes, row will be deleted.
I did it with setting Visible to true or false.
But I am not able to identify LinkButtons for Yes and No in DataGrid.
The main uestionn is, "how identify other objects in DataGrid row if I click on some object in that row.".
I need e.c. disable all the row before deleting.
Understand?
Thx 4 any help.
Zdenek.
You will need to use a CommandName for each of your controls in that cell. Let's assume that you have 5 columns in your datagrid. The last column has 3 controls a Delete Button, a Yes hyperlink, and a No hyperlink. Assign a CommandName to each control.
Delete Button Command Name = "Delete"
Yes Hyperlink CommandName = "Yes"
No Hyperlink CommandName = "No"
Now for the datagrid add an ItemCommand Event to the datagrid. Go to properties and click the lightning bolt to see the events of the datagrid. Double click on ItemCommand.
Now in your code behind file add the following code to the new datagrid event:
- //Make sure Yes and No linkbuttons are set to Visible = false;
-
Button buttonDelete = (Button) e.Item.Cells[4].FindControl("nameofyourDeletebutton");
-
LinkButton linkbuttonYes = (LinkButton) e.Item.Cells[4].FindControl("nameofyourYeshyperlink");
-
LinkButton linkbuttonNo = (LinkButton) e.Item.Cells[4].FindControl("nameofyourNohyperlink");
-
switch(e.CommandName)
-
{
-
case: "Delete"
-
linkbuttonYes.Visible = true;
-
linkbuttonNo.Visible = true;
-
buttonDelete.Visible = false;
-
break;
-
case: "Yes"
-
//call your delete proc here
-
//Make sure to rebind the grid after this so that row will be removed from the UI
-
linkbuttonYes.Visible = false;
-
linkbuttonNo.Visible = false;
-
buttonDelete.Visible = true;
-
break;
-
case: "No"
-
//Don't delete just show grid again in normal state
-
linkbuttonYes.Visible = false;
-
linkbuttonNo.Visible = false;
-
buttonDelete.Visible = true;
-
default:
-
break;
-
}
This should get you on the right track.
Nathan