asp.net: DetailsView control not interpreting html - asp.net

I have a asp.net detailsview control on a page. I've noticed that it always displays the raw text from my database field, it doesn't interpret the html in the text -- so it displays < b>mytext< /b> instead of just mytext in bold.
Is there anyway to get the control to interpret the html in the data being returned
Regards
melt

Can you post the code of your control? The basics are you need to set the HtmlEncode property to false. This is due to a difference in how labels and textboxes handle encoding, something meant to protect you from malicious scripts someone may have entered in these fields.
If you have it set to auto-generate fields (default), you'll need to change to BoundFields or TemplateFields instead and set the offending field's HtmlEncode Property to false.
You can see a code sample of the individual fields in MSDN, here's a simplified example:
<asp:DetailsView runat="server" AutoGenerateRows="False">
<Fields>
<asp:BoundField DataField="ProductName" HeaderText="Product" />
<asp:BoundField DataField="CategoryName" HeaderText="Category" />
<asp:BoundField DataField="HTMLField" HeaderText="HTML" HtmlEncode="false" />
</Fields>
</asp:DetailsView>

Related

How to develop a GridView with a column filled with Text Boxes

I have a GridView with 5 fields in jqQrid
<cc1:JQGrid ID="Qgrid" runat="server" Width="700px" Height="100%"
ondatarequesting="QgridDataRequesting"
onrowediting="QgridRowEditing">
<Columns>
<trirand:JQGridColumn Searchable="true"
SearchToolBarOperation="IsEqualTo" DataType="Int"
HeaderText="Order ID" PrimaryKey="True" ></trirand:JQGridColumn>
<trirand:JQGridColumn DataField='id' Visible="False"/>
<trirand:JQGridColumn DataField='last_name' Visible="False"/>
<trirand:JQGridColumn DataField='first_name' Visible="False"/>
<trirand:JQGridColumn DataField="opinion" Editable="True" />
</Columns>
<EditInlineCellSettings Enabled="True" />
<PagerSettings NoRowsMessage="No data in grid." />
<ToolBarSettings ShowEditButton="true" ShowRefreshButton="True" />
</cc1:JQGrid>
I wrote logic for events gridDataRequesting and gridRowEditing and now my license has expired
I want to write a simple gridview, but I don't know how to add a column with textbox's.
After leaving a textbox I want to I call "function grid RowEditing" (which executes a sql updating with the value from textbox)
Do you know any free plugin nearly like JqGrid?
If you are referring to editing the items in the gridview using text boxes, then you can check out this link. Here edit links are present that helps you in editing rows inline. The grid needs to be associated with an UpdateCommand. In your case that would execute the sql update. An alternative to gridRowEditing.
As for populating the data in the gridview, it can be done in the page load event of the aspx page. A possible alternative to gridDataRequesting in jqGrid.

ASP.NET Dynamic-data: Hot to add editable text column to readonly grid view

For displaying data in our application I've use GridView with the following markup:
<asp:GridView ID="listGridView" runat="server" DataSourceID="GridDataSource"
AllowPaging="True" AllowSorting="True"CssClass="gridview" AutoGenerateColumns="false" >
<Columns>
<asp:DynamicField DataField="App_Contact" />
<asp:DynamicField DataField="OldContact" />
<asp:DynamicField DataField="OldContactType" />
<asp:DynamicField DataField="NewContact" />
<asp:DynamicField DataField="NewContactType" />
<asp:DynamicField DataField="action_id" />
</Columns>
</asp:GridView>
Control with above grid is used as List control and display data in read only mode.
I would like add text box for each row and button for text box values saving.
I've create dynamic filed control (inherited from FieldTemplateUserControl), but control always invoked in readonly mode and property Mode always equal Read and control does not save data in databound source.
May be is exists any another way to add editable column to dynamic data List control?
The IDataBoundControl, IDataBoundListControl, IDataBoundItemControl and the IFieldControl interfaces expose the common properties that are required for Dynamic Data support. If you are creating a custom data-bound control that will work with Dynamic Data, you can implement these interfaces instead of deriving from the DataBoundControl class.

EmptyDataTemplate still shows message even if records found

I was wondering if any one could shed some light on property in the GridView. As far as I know, if no records are found, the text message inside
will be displayed, when the GridView control is bound to data. Actually, it’s working fine, but it works even if the record is found, too.
Currently, the datagridview is like this:
<asp:GridView ID="gvNomineeSearchResults" runat="server" DataKeyNames="ind_cst_key"
AutoGenerateColumns="false" AutoGenerateSelectButton="true"
OnSelectedIndexChanging="gvNomineeSearchResults_SelectedIndexChanged" OnRowCreated="gvNomineeSearchResults_RowCreated"
CssClass="selectedItems nominee" Width="100%" Caption="Search Results">
<Columns>
<asp:BoundField DataField="lastname" HeaderText="Last Name" NullDisplayText=" " />
<asp:BoundField DataField="firstname" HeaderText="First Name" NullDisplayText=" " />
</Columns>
<EmptyDataTemplate>
<p>Your search did not return any active AIAA Associate Fellows or did not find an email address on file for the individual you are searching for.</p>
</EmptyDataTemplate>
Any idea why the message is still showing even if records are found ?
Just Check the condition its correctly working or not.
Check the condition Gridview while Binding.
if(Dataset1.Items.count>0)
{
//Put your codes Here
}
Before Binding a Data to the Gridview Clear the Gridview Items.
Gridview1.Items.Clear();
Hope this may helpful....

Getting error when i click update using a gridview in vb.net

Im learning to use a gridview and a problem that im seeing is that putting an edit command in the gridview so that I can update a particular row. When I click the edit, it turns to the update as expected, I hit the update and the particular field turns the row into editable textboxes which is expected. The problem that I notice is that if I click another row, I get this error:
Invalid postback or callback argument. Event validation is enabled
using in configuration or <%#
Page EnableEventValidation="true" %> in a page. For security
purposes, this feature verifies that arguments to postback or callback
events originate from the server control that originally rendered
them. If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to
register the postback or callback data for validation.
My question is why is this error occuring? Here is my code gridview below:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" />
<asp:BoundField DataField="Product" HeaderText="Product" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:CommandField ShowEditButton="true" />
</Columns>
<SelectedRowStyle BackColor="#99CCFF" />
</asp:GridView>
It's impossible to tell what the specific issue is from the description you've provided, but you can probably work around the issue by disabling event validation.
Add the following to the page directive:
EnableEventValidation="false"
You should note that you lose some security benefits by doing this, but it should fix the error.

Data Displayed Twice In Gridview (ASP.NET)

I'm trying to make a page where information from the database are displayed on a page. For this, I'm using a Gridview control. The data displays fine, but it displays the same information twice. So basically, two tables are drawn by ASP and placed side by side.
Heres the code I'm using:
<asp:GridView ID="PackagesGV" runat="server" Width="520px">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Package ID"/>
<asp:BoundField DataField="PackageName" HeaderText="Package Name"/>
<asp:BoundField DataField="PackageText" HeaderText="Package Text"/>
<asp:BoundField DataField="PackageImageID" HeaderText="Package Image"/>
<asp:BoundField DataField="PageID" HeaderText="Page ID"/>
</Columns>
</asp:GridView>
Also, the SQL Stored Procedure is pulling all of the fields required by the Gridview. The SQL is basically
"SELECT [ID], [PackageName], [PackageText], [PackageImageID], [PageID] FROM [Packages]"
So I'm not requesting the information twice using the Stored Procedure.
I've started ASP.NET in July, so I apologise now if this is something really simple.
Thanks!
Michael
You need to either set the GridView.AutoGenerateColumns Property to false or not set up the columns.
If you choose the former method your grid definition will become:
<asp:GridView ID="PackagesGV" runat="server" Width="520px" AutoGenerateColumns="False">

Resources