EmptyDataTemplate still shows message even if records found - asp.net

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....

Related

in ASPX/VB using a gridview, how do I allow a checkbox on the row to be checked/unchecked without hitting some edit button?

I'm on an extreme time crunch, and its been years since doing any of this. I'm trying to take an old project, and enable a checkbox within the gridview.
My aspx gridview is:
<asp:GridView ID="grdReg" runat="server" AutoGenerateColumns="False" AllowSorting="True" EnableSortingAndPagingCallbacks="True" CssClass="table table-hover" GridLines="None">
<HeaderStyle CssClass="thead-dark" />
<Columns>
<asp:BoundField HeaderText="" DataField="pkID" ReadOnly="True"></asp:BoundField>
<asp:BoundField HeaderText="YourID" DataField="yourID" ReadOnly="True"></asp:BoundField>
<asp:BoundField HeaderText="Name" DataField="fullname" ReadOnly="True"></asp:BoundField>
<asp:BoundField HeaderText="Program" DataField="program" ReadOnly="True"></asp:BoundField>
<asp:BoundField HeaderText="Status" DataField="eStatus" ReadOnly="True"></asp:BoundField>
<asp:BoundField HeaderText="Recen" DataField="recent" ReadOnly="True"></asp:BoundField>
<asp:BoundField HeaderText="Enabled?" DataField="enabled" ReadOnly="False"></asp:BoundField>
</Columns>
</asp:GridView>
Now - the last column "Enabled?" is bound to a SQL Server bit field. Right now, when you display the aspx page - it shows 'True' or 'False' or blank if null.
Right now, I don't care if the field is a checkbox or shows the True/False - but when you click on it, I want it to toggle from T -> F or checked to unchecked. It's been too long since I've been in VB, and I need a simple way to accomplish this.
This will be a short term form, which is why I'm not terribly worried about "neatness" or polish. I just need it to work, and work quickly. If you give code snippets, PLEASE give them in context with the above code.
I finally solved by just clicking on the row to toggle the value. Not elegant, but works for now

Confirmation on GridView SelectedIndexChanging or SelectedIndexChanged

I have a GridView on an ASP page that has one bound field showing. Following is the code for this gridview.
<asp:GridView ID="GridView1" OnSelectedIndexChanging="confirmation" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ImportFileDescription" HeaderText="File Description" SortExpression="ImportFileDescription" ReadOnly="True" >
</asp:BoundField>
<asp:CommandField ShowSelectButton="True" SelectText="Import" ItemStyle-HorizontalAlign="Right" ButtonType="Button" />
</Columns>
</asp:GridView>
When a record or row is selected, I need to have a confirmation box pop up, and then a sub will be executed on the server. Fumbling my way through this, I had thought that using the CommandField Select Button would work, but I am having issues. I am not sold on using the CommandField to accomplish this, I would be open to whatever method would be easiest. I could also have a checkbox or something next to each row and then only one "Import" button at the bottom that would import all that are selected. It really doesn't matter as long as I have: (1) the ability to choose which records will be imported and (2) the ability to create the confirmation box.
Any help is greatly appreciated.

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">

asp.net: DetailsView control not interpreting html

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>

Resources