<asp:TemplateField Boxes Disappearing - asp.net

I've got a text box that just disappeared. When I add another templateField anywhere on the page, this one bizarelly disappears. Anyone know what might be up?
<asp:TemplateField HeaderText="Summary" SortExpression="summary">
<ItemTemplate>
<asp:Label ID="lblSummary" runat="server" Text='<%# Bind("summary") %>'></asp:Label>
</ItemTemplate>
<ItemTemplate>
<asp:TextBox ID="txtSummary" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("summary") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

<AnotherEdit>
I hope you don't take this wrong, and I mean no offense, but it seems like you're missing some of the basic concepts and need a good place to learn them.
Please check out the following article so that you fully understand how to use TemplateFields as opposed to a normal BoundField or a Command field. I think once you "get" it, your disappearing item issues will clear up because you'll be able to see it on your own.
http://www.asp.net/learn/data-access/tutorial-12-cs.aspx
</AnotherEdit>
You can't have more than one ItemTemplate in a TemplateField. You can have an EditItemTemplate and an ItemTemplate, though...
Edit - Added
The ItemTemplate shows when you're in normal display mode.
The EditItemTemplate shows when you're in edit mode
InsertItemTemplate shows when you're in Insert mode.
For any column in a GridView (or field in a FormView or field in a DetailsView) there can only be one TemplateField.
Within that TemplateField, there can only be one ItemTemplate, one EditItemTemplate, and one InsertItemTemplate (and not all three are required but all three are recommended.)
If you want the TextBox to show up next to the label in the normal non-edit mode, you would put the text box within the existing ItemTemplate as follows:
<ItemTemplate>
<asp:Label ID="lblSummary" runat="server" Text='<%# Bind("summary") %>'>
</asp:Label>
<asp:TextBox ID="txtSummary" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("summary") %>'>
</asp:TextBox>
</ItemTemplate>
However, the norm is to have the label when in read mode, and a text box when in edit or update mode like shown below:
<asp:TemplateField HeaderText="Summary" SortExpression="summary">
<ItemTemplate>
<asp:Label ID="lblSummary" runat="server" Text='<%# Bind("summary") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtSummary" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("summary") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtSummary" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("summary") %>'>
</asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>

You have multiple "ItemTemplate" declarations in there. There should be only one.

Related

asp.net Grid - how to wrap text in edit mode

I am displaying data(wrapped) in grid but when i am clicking on edit button is is not showing complete data because textbox is very small(data not wrapped). any help please...
Sample Code Line:
<asp:TemplateField HeaderText="Reason(NotDone)" SortExpression="tReason">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("tReason") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label17" runat="server" Text='<%# Bind("tReason") %>' ></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="SeaGreen" />
</asp:TemplateField>
........
On page load i am using the following code:
GridView1.Attributes.Add("style", "word-break:break-all; word-wrap:break-word");
Make the textbox a multiline.
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("tReason") %>'
TextMode="MultiLine"></asp:TextBox>
Thanks Akash & Michael for the quick response......i have done like this and it is working in grid .....please suggest if it is correct way ........asp:TemplateField HeaderText="Reason (If not Done)" SortExpression="tReason">
' TextMode="Multiline" Rows="10">
' >

How to set ItemTemplate text value to combobox DataTextField instead of DataValueField

I have a telerik radgrid with a GridTemplateColumn as seen below in a C# ASP.NET 4.0 webform.
As you can see, in the EditItemTemplate I am using a RadComboBox with an id number for DataValueField and a human readable text for DataTextField.
My question is, how can I change the Text in my ItemTemplate to show the human readable value instead of the Id? The value Alias1 comes from the grid datasource and it is the Id.
Thank you for any help you can provide!
<telerik:GridTemplateColumn UniqueName="Alias1" Display="true" DataField="Alias1" HeaderText="Alias1" SortExpression="Alias1">
<ItemTemplate>
<asp:Label ID="lblField30" CssClass="text" runat="server" Text='<%# Bind("Alias1") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox16" runat="server" Skin="Outlook" Height="150" DataSourceID="SqlDataSourceAliasOptions" DataTextField="aliasText" DataValueField="aliasid" SelectedValue='<%#Bind("Alias1") %>'>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
You need to change ItemTemplate binding like this:
<ItemTemplate>
<asp:Label ID="lblField30" CssClass="text" runat="server" Text='<%# Eval("aliasText") %>'></asp:Label>
</ItemTemplate>
Of course your binded entity must have "aliasText" property. If you are binding something like DataTable make sure that contains "aliasText" column.

asp.net gridview item template format currency

Possible duplicate Formatting DataBinder.Eval data
i want to change the format of an item template in a gridview, i want to show the currency..
this is my code:
<asp:TemplateField HeaderText="Monto">
<ItemTemplate><%# Eval("Monto")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtMonto" Text='<%# Eval("Monto", "{0:C2}")%>' /><%-- Eval("Price", "{0:C2}")--%>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfooterMonto" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="rfvMonto" controltovalidate="txtfooterMonto" Display="None"
errormessage="Monto" ValidationGroup="InsertValidationControls"/>
</FooterTemplate>
</asp:TemplateField>
You have formatting setup for editing here: EditItemTemplate
But not for viewing here: ItemTemplate

Databinding Error when Recreating object

Figure there is a simple solution to this problem but I have been unable to find it.
I have databinding in an ASP.Net application to a GridView. This gridview is bound to an ObjectDataSource as per standard usage.
The problem I have is that one of my bound fields uses the property DataFormatString="{0:C}" and due to the currency format being displayed when an update is attempted and the object recreated I get a error as such "$13.00 is not a valid value for Decimal."
Clearly this is a result of the column using a FormatString and then attempting to bind it back to a decimal property I have in my object called UnitPrice.
I am assuming there is some markup I can set that can specify how the value is translated back?
Thanks in advance for any help.
For anyone curious the solution ended up looking like this...
<asp:TemplateField>
<HeaderTemplate>
UnitPrice
</HeaderTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditItem" runat="server" Text='<%# Bind("UnitPrice", "{0:#,##0.00}") %>' Enabled="false" ></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("UnitPrice", "{0:c}") %>' ID="lblUnitPrice"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Do not include the format string in the EditItemTemplate. Just bind the raw value.
Something like this:
<asp:TemplateField SortExpression="UnitPrice" HeaderText="Unit Price">
<EditItemTemplate>
<asp:TextBox ID="editUnitPrice" Runat="server" Text='<%# Bind("UnitPrice", "{0:#,##0.00}") %>' ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("UnitPrice", "{0:c}") %>' ID="Label1"> </asp:Label>
</ItemTemplate>
</asp:TemplateField>

ASP.Net AJAX TabControl

I have placed an AJAX Tabcontrol on my page.
Inside the TabControl, I also placed a gridview.
<cc1:TabContainer id="tabconLandTransPlan" runat="server" Height="300px" ActiveTabIndex="0" AutoPostBack="True">
<cc1:TabPanel runat="server" ID="tabMasterPlan" HeaderText="Master Plan" >
<HeaderTemplate>
<span style="font-size: 8pt; font-family: Arial">Master Plan</span>
</HeaderTemplate>
<ContentTemplate>
<asp:GridView id="gvBuffer" runat="server" Width="100%" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Type of Services">
<HeaderStyle Width="26%"></HeaderStyle>
<ItemTemplate>
<asp:Label id="Label1" runat="server" Text='<%# EVAL("code_desc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tariff Code">
<HeaderStyle Width="4%" HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# EVAL("res_code") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</cc1:TabPanel>
When I retrieve the gridview, the gridview boundaries extend beyond the Tab Control boundaries. How Can I ensure that the gridview will be just within the boundaries of the tab control? The height of the Gridview is extending beyond the tab control. The width is just fine.
Thanks.
I may have found the answer to this little problem.
Apparently, the ajax tab control follows the size (height) of the controls inside it.
So what I did was set the height of the tabcontrol to Nothing (VB.Net).
Setting it to zero or any other percentage (conversion) values would otherwise throw an error.
Thanks to those who viewed.
Increase the height of the tab control!

Resources