HowTo: DataGrid edit mode for template columns?

A

Alex

I'm using a DataGrid with several bound columns. However for one column I
had to use a ItemTemplate with a asp:hyperlink in it.
How can I switch the hyperlink column into the edit mode in the datagrid
event handler?

Also, I sit possible to make not allow a field to be edited from within the
edit handler?
 
S

Scott Mitchell [MVP]

Alex said:
I'm using a DataGrid with several bound columns. However for one column I
had to use a ItemTemplate with a asp:hyperlink in it.
How can I switch the hyperlink column into the edit mode in the datagrid
event handler?

You need to provide an EditItemTemplate in the TemplateColumn.

<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink ... />
</ItemTEmplate>
<EditItemTemplate>
<asp:TextBox runat="Server" id="txtLinkEdit" Text='<%#
DataBinder.Eval(Container.DataItem, "hyperlinkFieldName")' />
</EditItemTemplate>
</asp:TemplateColumn>


To learn how to read the value of the edited TemplateColumn
programmatically, see:
http://datawebcontrols.com/faqs/ProgrammaticAccess/AccessingTemplateColumnContents.shtml

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
A

Alex

Thanks, works great!

Scott Mitchell said:
You need to provide an EditItemTemplate in the TemplateColumn.

<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink ... />
</ItemTEmplate>
<EditItemTemplate>
<asp:TextBox runat="Server" id="txtLinkEdit" Text='<%#
DataBinder.Eval(Container.DataItem, "hyperlinkFieldName")' />
</EditItemTemplate>
</asp:TemplateColumn>


To learn how to read the value of the edited TemplateColumn
programmatically, see:
http://datawebcontrols.com/faqs/ProgrammaticAccess/AccessingTemplateColumnContents.shtml

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

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,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top