templatefield

Converting an asp:ButtonField to an asp:TemplateField in a GridView Control

I currently have a gridview that has an asp:ButtonField as one of the columns. The event handler for the command extracts the row id of the gridview from the command argument and uses that to perform some logic. I now need to switch to using a template field for this column, and want to do something like this: <asp:TemplateField HeaderT...

Show HH:mm 24H format in TemplateField using text property

Hi there, im trying to show a 24 hours format using this line: Text='<%# Bind("Appointment", "{HH:mm}") So how it'll be formated for showing for example 16:40 instead 4:40 ? thanks in advance ...

How to use HtmlEncode with TemplateFields, Data Binding, and a GridView

I have a GridView bound to an ObjectDataSource. I've got it supporting editing as well, which works just fine. However, I'd like to safely HtmlEncode text that is displayed as we do allow special characters in certain fields. This is a cinch to do with standard BoundFields, as I just set HtmlEncode to true. But in order to setup vali...

ASP:LinkButton and Eval

I'm using an ASP:LinkButton inside of an ItemTemplate inside of a TemplateField in a GridView. For the command argument for the link button I want to pass the ID of the row from the datasource that the gridview is bound to, so I'm doing something like this: <asp:LinkButton ID="viewLogButton" CommandName="viewLog" CommandArgument="<%#Eva...

ASP:DropDownList in ItemTemplate: Why is SelectedValue attribute allowed?

This piece of code <asp:DropDownList runat="server" ID="testdropdown" SelectedValue="2"> <asp:ListItem Text="1" Value="1"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> <asp:ListItem Text="3" Value="3"></asp:ListItem> </asp:DropDownList> yields this error: The 'SelectedValue' property cannot be set ...

Adding TemplateField to DetailsView

How do I add TemplateField control to the beginning of the DetailsView Fields collection? Here is my code.. TemplateField tf = new TemplateField(); ... ... dv.Fields.Add(tf); This adds to the very end of the DetailsView control. I tried dv.Fields(0) but there is no Add method available. I noticed that we have dv.Fields.RemoveAt but w...

How to Sort on a GridView using ObjectDataSource with TemplateFields

Background: I am working with a GridView and an ObjectDataSource. I am implementing Paging and Sorting. On the ObjectDataSource: objectDataSource.TypeName = value; objectDataSource.SelectMethod = "Select"; objectDataSource.SelectCountMethod = "SelectCount"; objectDataSource.SortParameterName = "sortExp...

Can I programmatically add a linkbutton to gridview?

I've been looking through some similar questions without any luck. What I'd like to do is have a gridview which for certain items shows a linkbutton and for other items shows a hyperlink. This is the code I currently have: public void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Da...

Equivalence of an asp:HiddenField for a GridView

There is no asp:HiddenField that can be used in a GridView so I was wondering what would work similar to this. My reasoning for wanting this is I have a ButtonField that triggers an OnRowCommand. From there I can figure out which row was selected, but I cannot retrieve the text value from the ButtonField to see the data that was bound t...

Export Gridview TemplateField Problem to PDF

I am using iTexhSharp library to Export a Gridview Table with couple of BoundFields and TemplateFields, There is no problem with BoundFields, but All the TemplateFields are blank in Exported PDF File? Any Ideas? ...

Gridview looses ItemTemplate after columns are removed

I'm trying to bind a datatable to a gridview where I've removed some of the autogenerated columns in the code behind. I've got two template columns and it seems that when I alter the gridview in code behind and remove the non-templated columns that the templates loose the controls that are in them. Using the following as a sample, "He...

Overriding how Data is bound to Controls in a GridView

I'm not having much luck so far, so I am going to generalize my problem to see if there is a better way to accomplish what I neeed. Here is my scenario - I want a control that is defined in an aspx very similarly to a gridview. Something like this: <user:ReportView runat="server" id="rvData" > <Columns> <asp:BoundField Head...

ASP.net c# Gridview sorting with custom template fields

Hi all, I can't seem to figure out how to sort my gridview with both databound AND custom fields. The custom field look like this: <asp:Label ID="lblItems" runat="server" Text='<%# GetItems((int)DataBinder.Eval(Container.DataItem, "ObjectCategoryID"))%>' /> It calls for a function which shows how many item the given category has...

GridView Template - How to Grab Data from Selected Row

<asp:TemplateField> <ItemTemplate> <table width="540" cellpadding="5"> <tr> <td align="left" style="width:60%;"> <img src='PurchaseHandler.ashx?ProductID=<%# Eval("ProductID")%>' alt="<%# Eval("ProductName") %>" /> </td> <td align="left"> ...

ASP.Net: Sorting, GridView BoundColumn vs. TemplateColumn

With everything else being equal, a BoundField column in an asp:GridView is sortable, but a TemplateField column is not. Why is that? <asp:LinqDataSource ID="someDataSource" runat="server" ContextTypeName="someDataContext" TableName="someTable" OnSelecting="someSelectingHandler" /> ...

Binding the Checked Property of a CheckBox within a TemplateItem

For the life of me I cannot bind the Checked property of a CheckBox control within a TemplateField (declaritively). I have tried: <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="deactivated" runat="server" checked="<%#Eval("Deactivated")%>"></asp:CheckBox> </ItemTemplate> <...

Dynamic Gridview Template and Unique Control (ie textbox, label) IDs ?

When creating a Gridview at design time you can create a template column like this: <asp:TemplateField> <ItemTemplate> <asp:Label runat="server" ID="Label1"></asp:Label> </ItemTemplate> </asp:TemplateField> And in the HTML it will give it a unique name like: <span id="gvSelect_ctl02_Label1">blahblah</span> And I...

How to 2-way bind a textbox in a template fields programmatically.

Hi, I have a gridview to which I'm adding template fields programmatically. Each of the template fields have a textbox. I would like to make this text box have 2-way binding to a database column. Please see below code. public class CustomEditItemTemplate : ITemplate { private DataControlRowType templateType; private string columnName; ...

Using a TemplateField inside a web user control

Is it possible to use a TemplateField (or any *Field from a GridView) inside a user control (ascx). I have a complex TemplateField (item, edit, footer) that I would like to easily reuse. Thanks. ...

custom *arbitrary* TemplateField definitions

I'm building a GridView on the fly, and I'd like to pre-define the TemplateFields to be included ondemand. So, what I'd like to do is have a declarative file that defines how the different templates look for a specific column. Like: <asp:TemplateField> <HeaderTemplate> this is a text column </HeaderTemplate...