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

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
 
A

ata

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?
 
A

ata

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?
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top