I have a GridView and DetailsView on a page - both databound.
I want to select a databound row and open the modal with the populated DetailsView inside.
I have LinkButtons within a TemplateField for my select button with the sample bootstrap modal data-toggle and data-target fields.
My problem is with showing the DetailsView in the modal - upon clicking the SELECT button in the GridView - the modal shows, but the data is stays the same regardless of which row I select.
DetailsView Code
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DetailsViewComputer" Height="50px" Width="125px">
</asp:DetailsView>
<asp:SqlDataSource ID="DetailsViewComputer" runat="server" ConnectionString="<%$ ConnectionStrings:ITManagementConnectionString %>" ProviderName="<%$ ConnectionStrings:ITManagementConnectionString.ProviderName %>" SelectCommand="SELECT idComputers, idStatus, Hostname, idUser, AssetNumber, IPAddress, MACAddress, idoffice, idManufacturer, idModel, idProcessor, idRAM, idRAMType, idGraphicsCard, idHDD, SerialNumber, DateCreated, DateLastModified FROM computers WHERE (idComputers = #Param1)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Param1" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
GridView Code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="idComputers" DataSourceID="GridViewComputer">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select" data-toggle="modal" data-target="#myModal" Text="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="idComputers" HeaderText="idComputers" InsertVisible="False" ReadOnly="True" SortExpression="idComputers" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="Hostname" HeaderText="Hostname" SortExpression="Hostname" />
<asp:BoundField DataField="forename" HeaderText="forename" SortExpression="forename" />
<asp:BoundField DataField="surname" HeaderText="surname" SortExpression="surname" />
<asp:BoundField DataField="officename" HeaderText="officename" SortExpression="officename" />
<asp:BoundField DataField="IPAddress" HeaderText="IPAddress" SortExpression="IPAddress" />
<asp:BoundField DataField="ManufacturerName" HeaderText="ManufacturerName" SortExpression="ManufacturerName" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="HDDSize" HeaderText="HDDSize" SortExpression="HDDSize" />
<asp:BoundField DataField="RAMSize" HeaderText="RAMSize" SortExpression="RAMSize" />
</Columns>
</asp:GridView>
Through the process of elimination, I think the issue has something to do with my LinkButton - specifically with data-toggle - see below:
LinkButton1
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select" data-toggle="modal" data-target="#myModal" Text="Select"></asp:LinkButton>
Whenever I remove the data-toggle element and the DetailsView code from the Modal - the select works and the DetailsView displays the data. Whenever the data-toggle element is included and the DetailsView code is in the Modal - the Modal Shows without but the DetailsView data doesn't change.
Am I missing something?
I have searched and tried the solution in the below page, but either I'm an idiot or it didn't work (most likely the former):
Open popup with linkbutton
I would appreciate any help with this whatsoever! I have spent all day scratching my head because of this.
Thanks in Advance,
Chris
I found a solution to the issue by opening the Modal using JS - See below:
http://getbootstrap.com/javascript/#js-programmatic-api
I removed
data-toggle="modal" data-target="#myModal"
from LinkButton and instead added onClick="LinkButton1_Click" - see below:
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" OnClick="LinkButton1_Click" CommandName="Select" Text="Select"></asp:LinkButton>
I then referenced it in the VB.NET code behind:
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs)
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "myModal", "$('#myModal').modal()", True)
End Sub
Related
It convenient to do the query by :
<asp: AccessDataSource >
I wish to update the query string and update the result by a click event.
<asp:Button id="Button1"
Text="To Inquiry"
OnClick="doInquiry"
runat="server"/>
How I can achieve to update the query string and do the query in in the "doInquiry" function; BUT, still using the following useful code.
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Northwind.MDB" SelectCommand="SELECT * FROM [Categories]"></asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="AccessDataSource1" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
Whenever you generate the HTML via the markup and the behavior is different from what you expect, check the generated HTML in your browser. You intended to set the onclick attribute of an HTML tag, however, OnClick is a property pointing to the server-side method, which manages the server-side click event. You intended to use the OnClientClick property.
ASP.net(C#), VS2010, Win 7.
New to WebDev, so this might be a simple syntax thing but here it goes...
Long story short I have to force a postback on a GridView that shows attachments I upload using an ASPxUploadControl. I put the GridView inside an ASPxCallbackPanel and am trying to get my GridView to update on the page after an attachment is uploaded using ASPxCallbackPanel.PerformCallback();
Here's the Upload control, in its' ClientSideEvent is where I'm trying to call the clientSideEvent from the Button shown below. Just trying to force a button click really, but I tried doing it from the code-behind but that didn't work. Any help would be appreciated!
<dxuc:ASPxUploadControl ID="FileUpload1" runat="server"
ClientInstanceName="uploader"
ShowAddRemoveButtons="False"
ShowUploadButton="True"
AddUploadButtonsHorizontalPosition="Center"
AddUploadButtonsVerticalPosition="Top" FileInputCount="1"
UploadMode="Advanced"
OnFileUploadComplete="UploadControl_FileUploadComplete"
Size="30">
<ClientSideEvents FileUploadComplete="function(s, e) { Button1.Click; }" />
<%-- <AdvancedModeSettings EnableMultiSelect="True" /> "does not have public property named "advancedModeSettings" version is too old--%>
<ValidationSettings
AllowedFileExtensions=".doc,.pdf,.xls,.txt,.jpeg,.jpg,.gif,.png,.oft,.htm,.html,.mht,.rtf,.zip"
MaxFileSize="5242880"
FileDoesNotExistErrorText="This file can't be found."
GeneralErrorText="Custom file uploading fails due to an external error that doesn't relate to the ASPxUploadControl's functionality"
MaxFileSizeErrorText="Size of the uploaded file exceeds maximum file size">
<ErrorStyle ForeColor="Red"/>
</ValidationSettings>
</dxuc:ASPxUploadControl>
Here is the GridView as well as a button I made that successfully refreshes the grid.
<div>
<dxe:ASPxButton ID="ASPxButton1" runat="server" ClientInstanceName="Button1" Text="Reload Panel" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) {ASPxCallbackPanel1.PerformCallback(); e.processOnServer = true;}" />
</dxe:ASPxButton>
<dx:ASPxCallbackPanel ID="ASPxCallbackPanel1" runat="server"
ClientInstanceName="ASPxCallbackPanel1" Width="492px"
Height="100%">
<PanelCollection>
<dx:PanelContent runat="server">
<asp:GridView ID="gvAttachment" SkinID="grid" runat="server" Width="98%"
OnRowDataBound="AttachmentControl_OnRowDataBound"
meta:resourcekey="gvAttachResource1"
PagerSettings-FirstPageText="<%$ Resources:CommonControlText,FirstPageText %>"
PagerSettings-LastPageText="<%$ Resources:CommonControlText,LastPageText %>"
PagerSettings-PreviousPageText="<%$ Resources:CommonControlText,PreviousPageText %>"
PagerSettings-NextPageText="<%$ Resources:CommonControlText,NextPageText %>"
AutoGenerateColumns="False">
<EmptyDataRowStyle CssClass="emptyData" />
<EmptyDataTemplate>
<table class="usercontroldetail container_table">
<tr>
<td class="tdlayout">
<asp:Label ID="Localize1" runat="server">
<%= Placeholder %>
</asp:Label>
</td>
</tr>
</table>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="AtchmtId" HeaderText="Attachment ID"
visible = "false" meta:resourcekey="BoundFieldResource1">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField ="FileNm" HeaderText="File Name" />
<asp:BoundField DataField="UsrNm" HeaderText="Uploaded By"
/>
<asp:BoundField DataField="AtchmtDt" HeaderText="Date"
/>
<asp:BoundField DataField="FileSizeCnt" HeaderText="File Size"
/>
<asp:TemplateField AccessibleHeaderText="Actions" HeaderText="Actions">
<ItemTemplate>
<div style="text-align:center;">
<asp:LinkButton ID="btnDelete" Visible="False" runat="server"
ToolTip="Delete Selected Attachment"
OnClick="btnDelete_Click"
Text="Delete" CausesValidation="True" DisableOnSubmit="True" Group=""
meta:resourcekey="btnDeleteResource1" />
<asp:Label ID="lblPipe" runat="server" Text="|" />
<asp:LinkButton ID="btnView" Visible="False" runat="server"
ToolTip="View Selected Attachment"
OnClick="btnView_Click"
Text="View" CausesValidation="True" DisableOnSubmit="True" Group=""
meta:resourcekey="btnViewResource1" />
</div>
</ItemTemplate>
<ItemStyle Wrap="false" />
</asp:TemplateField>
</Columns>
<%--<PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next >" PreviousPageText="< Previous"></PagerSettings>--%>
<RowStyle CssClass="row_odd" />
<AlternatingRowStyle CssClass="row_even" />
</asp:GridView>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
FYI: The GridView is getting the new attachment put in it. I'm just not seeing it on the page because the UploadControl only updates itself.
Edit:Figured it out just used the OnClick() method as below. Derp. Forgot that the ASPx button inherited all the ASP buttons methods. But now my original plan of making the button invisible seems to be foiled. When Button1.OnClick() is called with the Visible property for the Button set to "false". it says Button1 is not defined. Anyway around this?
<ClientSideEvents FileUploadComplete="function(s, e) { Button1.OnClick(); }" />
If I got you right, you can manipulate the behavior of all update panels on page via property called a updateMode (Conditional, Always). Changing one updatepanel will cause refreshing of all, if all have mode set to Always.
I am using EntityDataSource control to display Data in Grid, I want to use the same EntityDataSource to display all data as well as per the search, the problem is I can do only one thing either can use it to search or to get whole data
here is my .aspx page
<asp:EntityDataSource ID="InvestorsSource" runat="server"
ConnectionString="name=Entities"
DefaultContainerName="Entities" EnableFlattening="False"
EntitySetName="Investors" EntityTypeFilter="Investor"
Select="it.[InvestorId], it.[InvestorName], it.[Summary], it.[Logo], it.[EmailAddress], it.[PhoneNumber], it.[Website]"
AutoGenerateWhereClause="True" OrderBy="it.[InvestorName]">
<WhereParameters>
<asp:FormParameter FormField="txtSearchInvestor" Name="investorName" Type="String" />
</WhereParameters>
</asp:EntityDataSource>
<asp:TextBox ID="txtSearchInvestor" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Go" onclick="Button1_Click" />
<p>
<asp:GridView ID="gvInvestors" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="InvestorsSource">
<Columns>
<asp:BoundField DataField="InvestorId" HeaderText="InvestorId" ReadOnly="True"
SortExpression="InvestorId" />
<asp:BoundField DataField="InvestorName" HeaderText="InvestorName"
SortExpression="InvestorName" ReadOnly="True" />
<asp:BoundField DataField="Summary" HeaderText="Summary"
SortExpression="Summary" ReadOnly="True" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"
SortExpression="EmailAddress" ReadOnly="True" />
<asp:BoundField DataField="PhoneNumber" HeaderText="PhoneNumber"
SortExpression="PhoneNumber" ReadOnly="True" />
<asp:BoundField DataField="Website" HeaderText="Website"
SortExpression="Website" ReadOnly="True" />
</Columns>
</asp:GridView>
</p>
Thanks
I setup a page using the Northwind DB and using the Employees table. There is a TextBox control and Button controls just like your code to filter the data. When the TextBox is empty, all records are displayed. When a EmployeeID is entered into the TextBox, and the 'Filter' button is clicked, only the employee with the EmployeeID is displayed(if present in the data). I think this is the kind of behavior you are asking for. Here is the markup:
<form id="form1" runat="server">
<div>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=NWEntities" DefaultContainerName="NWEntities"
EntitySetName="EmployeeSet" EntityTypeFilter="Employee" AutoGenerateWhereClause="true"
Select="it.[EmployeeID], it.[LastName], it.[FirstName], it.[Title], it.[TitleOfCourtesy], it.[BirthDate]">
<WhereParameters>
<asp:FormParameter FormField="txtFilter" Name="EmployeeID" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
<asp:TextBox ID="txtFilter" runat="server" />
<asp:Button runat="server" Text="Filter" />
<asp:GridView ID="gvEmployees" runat="server" DataSourceID="EntityDataSource1" AutoGenerateColumns="true" />
</div>
</form>
Edit: The question has been raised as how part of a value could be entered into the filter text box to get all the values that start with the entered value. You could use the LIKE SQL operator and the users would need to be told that the "%" character is the wildcard. I changed the filter to the FirstName field. Here are the changes to the above code:
In the EntityDataSource tag:
AutoGenerateWhereClause="false"
Where="it.[FirstName] LIKE #FirstName"
In the WhereParameters tag:
<asp:FormParameter FormField="txtFilter" Name="FirstName" Type="String" DefaultValue="%" />
Now, when "n%" is entered into the filter textbox, all records with a FirstName value that starts with "n" will be displayed. Any valid LIKE clause could now be used.
I have a gridview which I am binding through code behind, I want to filter the gridview based on the value given by the user in textbox.
It would be great if I'll be able to filter the gridview without any postback.
PLease help!
Thanks in advance
you could run a filter expression
<asp:sqldatasource id="articles" runat="server"
connectionstring="<%$ ConnectionStrings:aspa %>"
selectcommand="SELECT title, url, added, updated FROM aspx_articles ORDER BY title"
filterexpression="title LIKE '%{0}%' or url LIKE '%{0}%'">
<filterparameters>
<asp:controlparameter controlid="searchBox" propertyname="Text" />
</filterparameters>
</asp:sqldatasource>
or this way
Do you have a TextBox outside the GridView, and when you enter data into it and press a button, the GirdView should be filter on that data?
If so, make sure your select command can taka a parameter with the value you want to filter on. Add a ControlParameter to the SelectParameters colelction of the DataSource control (if you use a DataSource control).
Here is an example that uses the Northwind database, maybe this will help you:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ShowFooter="True">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitsInStock], [UnitPrice] FROM [Alphabetical list of products] WHERE ([ProductName] LIKE '%' + #ProductName + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="%" Name="ProductName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
codes found here http://forums.asp.net/p/1034014/2904713.aspx
If you're using paging, I would recommend using something else (like the Microsoft Ajax Library's dataView). Because gridview paging and client-side filtering wouldn't mesh too well. But if you're not doing paging, you could do something similar to this or this.
The grid view is made for manipulation during post back. If you were to do this entirely on the client side, you'd use a JavaScript suite that would work on any table, not confined to the grid view. If it were me, I would simply use AJAX by wrapping the grid view and text box in an Update Panel. To the end user, the behavior is the same.
EDIT to include Sample code:
<asp:ScriptManager ID="ScriptManager1" AllowCustomErrorsRedirect="false" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="txtFilterString" ></asp:TextBox>
<asp:Button runat="server" ID="btnFilter" Text="FilterResults" onclick="btnFilter_Click" />
<asp:GridView runat="server" ID="grdResults"
DataKeyNames="Id"
AllowSorting="true" AllowPaging="true" PageSize="20"
PagerSettings-Mode="NumericFirstLast">
<Columns>
.....
</Columns>
</asp:GridView>
</asp:UpdatePanel>
I have a GridView that renders books from a database.
In each line a Delete/Edit button is rendered. When the user clicks the Edit button, I want the the Cancel and Update buttons to appear and the Edit buttton to become disabled.
I thought about using the onClick event for the Edit button along with the GridView row for getting the appropriate button based on the row, setting the Edit button's Enable property to false and the visibility of the Cancel and Update buttons to true.
However, it seems I can not change the properties even for the Edit button that I get from the event handler.
Here is the code.
protected void EditButton_Click(object sender, EventArgs e)
{
Button Sender = (Button)sender;
Sender.Text = "??"; //THIS CHANGE IS NOT APPLIED!!
//Button Sender = (Button)sender;
//GridViewRow grdRow = (GridViewRow)Sender.Parent.Parent;
//Button btn = (Button)grdBooks.Rows[grdRow.RowIndex].Cells[1].FindControl("CancelButton");
}
<asp:GridView
id="grdBooks"
DataSourceID="srcBooks"
DataKeyNames="Product_ID"
AutoGenerateColumns="false"
CssClass="products"
GridLines="none"
Runat="server" OnRowCreated="grdBooks_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button CausesValidation="false" ID="DeleteButton" CommandName="Delete" runat="server" Text="Delete" />
<asp:Button CausesValidation="false" ID="EditButton" CommandName="Edit" runat="server" Text="Edit" OnClick="EditButton_Click" />
<asp:Button CausesValidation="false" ID="CancelButton" Enabled="false" Visible="true" CommandName="Cancel" runat="server" Text="Cancel" />
<asp:Button CausesValidation="false" ID="UpdateButton" Enabled="false" Visible="true" CommandName="Update" runat="server" Text="Update" />
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:CommandField ButtonType="Button" ShowEditButton="true"/>--%>
<asp:BoundField
DataField="ISBN"
ReadOnly="true"
HeaderText="ISBN" />
<asp:BoundField
DataField="Title"
ReadOnly="true"
HeaderText="Title" />
<asp:BoundField
DataField="First_Name"
ReadOnly="true"
HeaderText="First Name" />
<asp:BoundField
DataField="Last_Name"
ReadOnly="true"
HeaderText="Last Name" />
<asp:BoundField
DataField="Price"
HeaderText="Price" />
<asp:BoundField
DataField="Quantity"
HeaderText="Quantity" />
</Columns>
</asp:GridView>
After the event is handled, the page probably reloads and resets the original text.
Maybe you could use JavaScript to do what you need.
Ok, it's very simple after all, there is this beautiful tag within the GridView that does exactly what i want..
Thanks for viewing, hope this post helps more niewbies..
<EditItemTemplate>
<asp:Button CausesValidation="false" ID="CancelButton" CommandName="Cancel" runat="server" Text="Cancel" />
<asp:Button CausesValidation="false" ID="UpdateButton" CommandName="Update" runat="server" Text="Update" />
</EditItemTemplate>