How to put a GridView's row in edit mode, programatically?

  • Thread starter Thread starter ata
  • Start date Start date
A

ata

Hi folks,
I've got a LinkButton that's being added to the GridView under certain
circumstances, conditionally.
Whenever the link is clicked, I would like to put the row (that
contains the link) in edit mode.
Please note that I'm trying to do this dynamically, in the run-time.

Any help would be highly appreciated,

Thanks
Jack
 
Just make sure that your linkbutton has the property CommandName="Edit".

Well, I did so, but it doesn't work yet. Here's the code:

LinkButton lblOptions = new LinkButton();
lblOptions.CommandName = "Edit";
lblOptions.CausesValidation = false;
lblOptions.ID = "lblOptions" + id;
lblOptions.Text = String.Format("<span style='margin-left:10px;'></
span>{0} other options", total);
lblOptions.Style.Add(HtmlTextWriterStyle.Color, "black");
lblOptions.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
lblOptions.Style.Add(HtmlTextWriterStyle.FontSize, "7pt");

row.Cells[3].Controls.Add(lblOptions);

Pressing the link doesn't put the row in Edit mode!
Any idea?
 
Just make sure that your linkbutton has the property CommandName="Edit".

Well, I did so, but it doesn't work yet. Here's the code:

LinkButton lblOptions = new LinkButton();
lblOptions.CommandName = "Edit";
lblOptions.CausesValidation = false;
lblOptions.ID = "lblOptions" + id;
lblOptions.Text = String.Format("<span style='margin-left:10px;'></
span>{0} other options", total);
lblOptions.Style.Add(HtmlTextWriterStyle.Color, "black");
lblOptions.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
lblOptions.Style.Add(HtmlTextWriterStyle.FontSize, "7pt");

row.Cells[3].Controls.Add(lblOptions);

Pressing the link doesn't put the row in Edit mode!
Any idea?

WowI Actually find the problem. The link is created based
e.Row.DataItem, in the RowCreated event handler.
However, I've just noticed that when the link button is pressed, the
RowCreated function gets called,
but this time, e.Row.DataItem is null!!!!!!

How this can be possible?
 
Back
Top