Confirmation on GridView SelectedIndexChanging or SelectedIndexChanged - asp.net

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.

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

ASP.Net - Sorting a GridView without postback (bound to a generic list)

I'm trying to sort the columns for a GridView in ASP.Net, ideally without refreshing the page.
My data is compiled into a generic list on the server and bound to the GridView in the code-behind.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" CellPadding="3" GridLines="Vertical" AllowSorting="True"
CssClass="GridViewStyle" EnableSortingAndPagingCallbacks="True"
AllowPaging="True">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID">
</asp:BoundField>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title">
</asp:BoundField>
<asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer">
</asp:BoundField>
</Columns>
When I try to click any of the column headers, nothing happens.
Is there any way to accomplish this without refreshing the page?
No, there is no way to accomplish this with a Gridview alone without causing a postback.
You can sort it on the client side with JavaScript (perhaps by abandoning GridView and instead using a Repeater combined with jQuery DataTables)
Or you can use an UpdatePanel or iframe to mask the postback. Those have their own complications and are probably not the best approach however. I personally absolutely hate using either of them and recommend you steer clear.

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

Can we avoid postback in gridView...when user click a button in same?

I have a gridview ...in my dotnet 2.0 - web application.
gridview has 2 columns...first column is ID..and second is a "link button"..as shown below.
On click of this link, I have to display a popup..and I'm using ajax ModalPopupExtender.
I am able to see the popup.
But the issue is...when I click on this link button the postback happens...and the gridview.datasource is NULL. So I have to fetch the data from database and bind the gridview again.
Please help me to find a way to avoid this.
<asp:GridView ID="AvailableGridView" >
<Columns>
<asp:BoundField ItemStyle-CssClass="ItemStyleCss" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="GridHeaderRow" HeaderText="ID" DataField="ClaimCodeGroupIdText"
/>
<asp:TemplateField HeaderText="View" ShowHeader="False"> <ItemTemplate>
<asp:LinkButton CssClass="localNavigation" ID="ViewCCGLinkButton"
Text="View" CommandName="View" CommandArgument='<%# Eval("ClaimCodeGroupId") %>' runat="server"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle CssClass="GridHeaderRow" />
</asp:TemplateField>
</Columns>
<asp:GridView />
You can set ajax toolkit modal popup to load client side and not cause a postback.
But if you have to get data from the server side, i think you have following options
Use ajax to load server data
Save the selected Id in the hidden text box and on postback read Id thru hidden textbox
Use jQuery BlockUI and ajax to load server data (personal fav.)
Pick your options according to ur need and requirement.

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