Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding and Removing Edit / Delete Columns to a DataGrid on the fly

Status
Not open for further replies.

GavW

Programmer
Jan 13, 2006
58
GB
Hey all!

I am trying to establish an administration style feature to my datagrid by providing an option to "switch on" an edit and delete column. I currently have the following code:

private void btnAdminOn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
btnAdminOff.Visible = true;
btnAdminOn.Visible = false;

EditCommandColumn edit = new EditCommandColumn();
// edit.ButtonType = "PushButton";
edit.UpdateText = "Update";
edit.CancelText = "Cancel";
edit.EditText= "Edit";

ButtonColumn delete = new ButtonColumn();
delete.Text = "Delete";
delete.CommandName = "Delete";

DataGrid1.Columns.Add(edit);
DataGrid1.Columns.Add(delete);

if ( !IsPostBack )
{
DataGrid1.DataSource = ds;
DataGrid1.DataBind ( );
}
}

The reason i have the "ButtonType" line of code commented out is due to an error i was receiving: "Cannot implicitly convert type 'string' to System.Web.UI.WebControls.ButtonColumnType'"

Could this be the reason i am having no luck?

Thanks in advance for any help.

GavW
 
It wants an Enum value. I don't have it in front of me, but something like ButtonColumnType.PushButton or something.


----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Okay, I fired up Visual Studio and it is what I said, so your code will build like the following

Code:
EditCommandColumn edit = new EditCommandColumn();
			edit.ButtonType = ButtonColumnType.PushButton;
			edit.UpdateText = "Update";
			edit.CancelText = "Cancel";
			edit.EditText= "Edit";

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Cheers mate for sorting that out for me, it compiles now. Unfortunately i still cannot get these columns to display as part of my datagrid.

Is there a line of code somewhere that i am missing out that displays these two new columns?

GavW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top