How to add empty Caption in ASP.net gridview - asp.net

Whenever I set caption property to blank in an ASP.net gridview it does not show up in html. how can I add empty caption in gridview so that in html it shows up as <caption/> rather than not showing up at all.
<asp:GridView ID="gvClients" runat="server" Caption="">

Can you please say in more details, why you require tag if there is no any text for the grid or table header?
If you require it by specific reason then you can add the space as below in your code.
<asp:GridView ID="gvClients" runat="server" Caption=" ">

Related

ASP.Net GridView styling - invisible cell lining

I`m using a Gridview in an ASP.Net web app.
Since it has custom styling and templates, I couldn't figure how to style it the way I want. I want all the lines of the final HtmlTable to be invisible - just purely the cellcontent and margins between them, without a visible table. How can I do such a thing?
The gridView itself:
<asp:GridView
ID="Items" runat="server">
</asp:GridView>
<asp:GridView
ID="Items" runat="server" GridLines="None"
CellSpacing="Set a Value" CellPadding="Set a Value">
</asp:GridView>

How do I convert asp:textbox to freetextbox

I have an asp:TextBox that I need to convert to a FreeTextBox. The following is my asp:TextBox aspx code:
<%# Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
<asp:TextBox ID="tbxRiskDesc" runat="server" Width="90%" TextMode="MultiLine" Rows="6" onblur="Resize(this);" onkeypress="Resize(this);" ></asp:TextBox>
<rad:RadSpell ID="spellRiskDesc" runat="server" Width="5px" ControlToCheck="tbxRiskDesc" WordIgnoreOptions="UPPERCASE" FragmentIgnoreOptions="EmailAddresses,Urls" DictionaryLanguage="en-AU" SupportedLanguages="en-AU,English" AllowAddCustom="true" DictionaryPath="~/RadControls/Spell/TDF/" SpellCheckProvider="EditDistanceProvider" EditDistance="2" ButtonType="ImageButton" />
The following code is in the aspx.cs code:
Page_Load:
tbxRiskDesc.Attributes.Add("onchange", "setDirty();");
Reset_Data:
SetTextCurrentValue(tbxRiskDesc, dtEditTable, "RiskDesc");
Clear_Data:
SetTextValue(tbxRiskDesc, "RISK TITLE & DESC.:");
When I replace the "asp:TextBox" code in the aspx file with the following, the code behind has errors and i dont know how to change the code for the FreeTextBox for the Page_Load, Reset_Data & Clear_Data sections.
<FTB:FreeTextBox ID="tbxRiskDesc" runat="server"></FTB:FreeTextBox>
The reason for the change over is because we need to allow the users to put bullet points and hyperlinks into the text boxes.
All help is appreciated.
You have two options:
recommended: replace the textbox with RadEditor which has built-in integration with RadSpell
use the RadSpell API to spellcheck the FreeTextBox control: You have to get a reference to the body element of the iframe content area of FreeTextBox. After that you can implement a custom text source similarly as it is done for RadEditor in the following forum thread: Problem with spellcheck.
Using the RadEditor's get_contentAreaElement() method you can get a reference to RadEditor's iframe content area element and after that to get a reference to the body tag of the iframe:
var editorSource = $find('RadEditor1').get_contentAreaElement().contentWindow.document.body;
You should see in the FreeTextBox documentation or forums how to get a reference to the body element and update the above line in the provided in the forum article custom text source code.

Is to set SelectedRowStyle attribute a bad idea to change the background color of a selected row?

What I want to achieve is to change the backtroung color of the selected row in a gridview.
I have the command field.
And I set the SelectedRowStyle="highlight" class.
But when I select the row, nothing changes :(
I know I can do some changes on Gridview event on the code behind. But I should be able to achive this just by a simple mark-up change instead of writing code to set CssStyle of each cell.
Pelase, can you see what am I doing wrong?
<asp:GridView ID="gvResults" runat="server" OnRowCommand="GridViewResults_RowCommand"
SelectedRowStyle="highlight">
<Columns>
<!-- Some bound fields here -->
<asp:CommandField SelectText="Select >>" ShowSelectButton="true"/>
</Columns>
Change the SelectedRowStyle to SelectedRowStyle-CssClass property

GridView ImageField With Text

I have an ASP.Net GridView and I want to include an Image and a Text in the same field, something like this:
<a id="lnkForJQueryCall"><img src="whatever.png"> Some Other Number</a>
I have found the asp:ImageField does not have a Property for adding a text at right or left of the image, and there are no much options, is there any way to achieve it?
[EDIT] I was thinking of a css class workaround but have not figured out how to do it !!
You can use a TemplateField to display custom content in a data-bound control such as a GridView.
<asp:TemplateField>
<ItemTemplate>
<a id="lnkForJQueryCall"><img src="whatever.png"> Some Other Number</a>
</ItemTemplate>
</asp:TemplateField>

Using Panel or PlaceHolder

What is the difference between <asp:Panel > and <asp:PlaceHolder > in ASP.NET?
When should you use one over the other?
A panel expands to a span (or a div), with it's content within it. A placeholder is just that, a placeholder that's replaced by whatever you put in it.
The Placeholder does not render any tags for itself, so it is great for grouping content without the overhead of outer HTML tags.
The Panel does have outer HTML tags but does have some cool extra properties.
BackImageUrl: Gets/Sets the
background image's URL for the panel
HorizontalAlign: Gets/Sets the
horizontal alignment of the parent's
contents
Wrap: Gets/Sets whether the
panel's content wraps
There is a good article at startvbnet here.
PlaceHolder control
Use the PlaceHolder control as a container to store server controls that are dynamically added to the Web page. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page. You can use the Control.Controls collection to add, insert, or remove a control in the PlaceHolder control.
Panel control
The Panel control is a container for other controls. It is especially useful when you want to generate controls programmatically, hide/show a group of controls, or localize a group of controls.
The Direction property is useful for localizing a Panel control's content to display text for languages that are written from right to left, such as Arabic or Hebrew.
The Panel control provides several properties that allow you to customize the behavior and display of its contents. Use the BackImageUrl property to display a custom image for the Panel control. Use the ScrollBars property to specify scroll bars for the control.
Small differences when rendering HTML: a PlaceHolder control will render nothing, but Panel control will render as a <div>.
More information at ASP.NET Forums
I weird bug* in visual studio 2010, if you put controls inside a Placeholder it does not render them in design view mode.
This is especially true for Hidenfields and Empty labels.
I would love to use placeholders instead of panels but I hate the fact I cant put other controls inside placeholders at design time in the GUI.
As mentioned in other answers, the Panel generates a <div> in HTML, while the PlaceHolder does not. But there are a lot more reasons why you could choose either one.
Why a PlaceHolder?
Since it generates no tag of it's own you can use it safely inside other element that cannot contain a <div>, for example:
<table>
<tr>
<td>Row 1</td>
</tr>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</table>
You can also use a PlaceHolder to control the Visibility of a group of Controls without wrapping it in a <div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible="false">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:PlaceHolder>
Why a Panel
It generates it's own <div> and can also be used to wrap a group of Contols. But a Panel has a lot more properties that can be useful to format it's content:
<asp:Panel ID="Panel1" runat="server" Font-Bold="true"
BackColor="Green" ForeColor="Red" Width="200"
Height="200" BorderColor="Black" BorderStyle="Dotted">
Red text on a green background with a black dotted border.
</asp:Panel>
But the most useful feature is the DefaultButton property. When the ID matches a Button in the Panel it will trigger a Form Post with Validation when enter is pressed inside a TextBox. Now a user can submit the Form without pressing the Button.
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Input is required" ValidationGroup="myValGroup"
Display="Dynamic" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="myValGroup" />
</asp:Panel>
Try the above snippet by pressing enter inside TextBox1

Resources