At the moment i have a link button that when it is clicked it will download a file. Is it possible to have an onclick pop up where the user can select if he wants to download or delete the file?
P.s New to asp.net and C#
<asp:GridView ID="FileTableView" CssClass="datagrid" HeaderStyle-CssClass="datagridHeader" RowStyle-CssClass="datagridRows" runat="server" AutoGenerateColumns="False" DataKeyNames="fileid, filename">
<Columns>
<asp:TemplateField HeaderText="Master Folder">
<ItemTemplate>
<asp:LinkButton ID="FileLinkButton" OnClick="DownloadFile" runat="server" Text='<%# Eval("filename") %>' FileID='<%# Eval("fileid") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You could use Bootstrap to display the modal popup, all you have to do is add these three references to your project:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
Complete solution can be found below:
Code behind:
public class MyFile
{
public int fileid { get; set; }
public string filename { get; set; }
}
public partial class PopupInGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var f1 = new MyFile { fileid = 1, filename = "File 1" };
var f2 = new MyFile { fileid = 2, filename = "File 2" };
var files = new List<MyFile> { f1, f2 };
FileTableView.DataSource = files;
FileTableView.DataBind();
}
}
protected void File_Command(object sender, CommandEventArgs e)
{
string command = e.CommandName;
string fileId = Session["fileid"] as string;
switch (command)
{
case "ShowPopup":
Session["fileid"] = e.CommandArgument;
ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "showPopup();", true);
break;
case "Delete":
//Your delete logic...
break;
case "Download":
//Your download logic...
break;
}
}
}
.ASPX:
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script type="text/javascript">
function showPopup() {
$('#myModal').modal('show');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView
ID="FileTableView"
CssClass="datagrid"
HeaderStyle-CssClass="datagridHeader"
RowStyle-CssClass="datagridRows"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="fileid, filename">
<Columns>
<asp:TemplateField HeaderText="Master Folder">
<ItemTemplate>
<asp:LinkButton ID="lnkChoice" CommandName="ShowPopup" OnCommand="File_Command" CommandArgument='<%# Eval("fileid") %>' runat="server" Text='<%# Eval("filename") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Delete or download?</h4>
</div>
<div class="modal-body">
<asp:Button ID="btnDelete" CommandName="Delete" CommandArgument="" runat="server" Text="Delete" OnCommand="File_Command" />
<asp:Button ID="btnDownload" CommandName="Download" CommandArgument="" runat="server" Text="Download" OnCommand="File_Command" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
</body>
Related
How can I select the record in the grid view and delete or edit this record? In Asp.Net Web Form
I want this to be done with the Bootstrap modal
I do this with Entity Framework
I have only been able to code to add
The methods I know for editing and deleting are not suitable for this project and they do not work on Bootstrap Modal
Html Code:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ProductControl.aspx.cs" Inherits="AppData.Pages.ProductControl" %>
<asp:Content ID="HeadContent" ContentPlaceHolderID="Head" runat="server">
<script src="../Scripts/jquery-3.6.0.slim.min.js"></script>
<script src="../Scripts/Site.js"></script>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="container">
<div class="row">
<div class="col-md-12 table-responsive" id="ProductDiv">
<div class="d-flex justify-content-between align-items-center mb-3 mt-3">
<h4>List of Products</h4>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#ModalAdd">
Add Product
</button>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:GridView ID="GridView" runat="server" CssClass="table text-center table-bordered table-hover" HeaderStyle-CssClass="table-dark" AutoGenerateColumns="false" DataKeyNames="Id" OnRowCommand="GridView_RowCommand">
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Font-Size="Small">
<HeaderTemplate>Row</HeaderTemplate>
<ItemTemplate><%# Container.DataItemIndex+1 %></ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:BoundField DataField="Type" HeaderText="Type" />
<asp:BoundField DataField="Barcode" HeaderText="Barcode" />
<asp:TemplateField HeaderText="Commands" ItemStyle-Font-Size="Small">
<ItemTemplate>
<asp:LinkButton CssClass="btn btn-warning" ID="BtnEdit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton CssClass="btn btn-danger" ID="BtnDelete" runat="server" data-toggle="modal" data-target="#ModalDelete">Delete</asp:LinkButton>
<asp:LinkButton CssClass="btn btn-info" ID="BtnDetail" runat="server">Detail</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div class="row">
<asp:Label ID="LblNotFound" runat="server" Text="No Product Found" CssClass="col-12 alert alert-danger text-center" Visible="false"></asp:Label>
</div>
</div>
<!-- Modal Add -->
<asp:UpdatePanel ID="UpdatePanelModalAdd" runat="server">
<ContentTemplate>
<div class="modal" id="ModalAdd">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add New Record</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-6">
<p>Name:</p>
<asp:TextBox ID="Name" placeholder="Name" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="col-6">
<p>Price:</p>
<asp:TextBox ID="Price" placeholder="Price" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</div>
<div class="row">
<div class="col-6">
<br />
<p>Type:</p>
<asp:TextBox ID="Type" placeholder="Type" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="col-6">
<br />
<p>Barcode:</p>
<asp:TextBox ID="Barcode" placeholder="Barcode" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="BtnCreate" runat="server" CssClass="btn btn-success" Text="Create" OnClick="BtnCreate_Click" />
<asp:Button ID="BtnCancel" runat="server" CssClass="btn btn-danger" Text="Cancel" data-dismiss="modal" />
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnCreate" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="BtnCancel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<!-- Modal Detail -->
<asp:UpdatePanel ID="UpdatePanelModalDetail" runat="server">
<ContentTemplate>
<div class="modal" id="ModalDetail">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Detail Record</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-6">
<p>Name:</p>
<asp:Label ID="LblName" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
<div class="col-6">
<p>Price:</p>
<asp:Label ID="LblPrice" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
</div>
<div class="row">
<div class="col-6">
<br />
<p>Type:</p>
<asp:Label ID="LblType" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
<div class="col-6">
<br />
<p>Barcode:</p>
<asp:Label ID="LblBarcode" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="Button1" runat="server" CssClass="btn btn-success" Text="Create" OnClick="BtnCreate_Click" />
<asp:Button ID="Button2" runat="server" CssClass="btn btn-danger" Text="Cancel" data-dismiss="modal" />
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<!-- Modal Delete -->
<asp:UpdatePanel ID="UpdatePanelModalDelete" runat="server">
<ContentTemplate>
<div class="modal" id="ModalDelete">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Delete Record</h4>
</div>
<div class="modal-body">
<h6 class="text-center">Are you sure you want to delete this record?</h6>
<br />
<div class="text-center">
<asp:Button ID="Delete" CssClass="btn btn-danger border-2 border-dark" runat="server" Text="Delete" CommandArgument='<%# Eval("Id") %>' CommandName="Delete" />
<button id="Cancel" class="btn btn-light border-2 border-dark" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Delete" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</asp:Content>
And Backend Code:
using AppData.Models;
using System;
using System.Collections.Generic;
using System.EnterpriseServices;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AppData.Pages
{
public partial class ProductControl : System.Web.UI.Page
{
Models.ProductDbEntities Db = new Models.ProductDbEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (GridView.Rows.Count > 0)
{
LblNotFound.Visible = false;
}
else
{
GridView.DataSource = Db.TblProducts.ToList();
GridView.DataBind();
}
}
protected void BtnCreate_Click(object sender, EventArgs e)
{
TblProduct Row = new TblProduct();
Row.Name = Name.Text;
Row.Price = Price.Text;
Row.Type = Type.Text;
Row.Barcode = Convert.ToInt64(Barcode.Text);
Db.TblProducts.Add(Row);
Db.SaveChanges();
Response.Redirect("ProductControl.aspx");
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("Pages/ProductControl.aspx");
}
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
var id = e.CommandArgument;
if (e.CommandName == "Delete")
{
Int64 Id = Convert.ToInt64(id);
var Row = Db.TblProducts.FirstOrDefault(n => n.Id == Id);
Db.TblProducts.Remove(Row);
Db.SaveChanges();
Response.Redirect("DataControl.aspx");
GridView.DataSource = Db.TblProducts.ToList();
GridView.DataBind();
}
}
}
}
I understand your approach, but if you are using bootstrap modals you need to write a little bit more code.
One way to achieve this is by following the next steps:
In the Delete modal add a hidden field to hold the selected productId and an event handler for the delete button:
<div class="modal-body">
<h6 class="text-center">Are you sure you want to delete this record?</h6>
<br />
<!--add this inside delete modal -->
<input type="hidden" id="productIdToDelete" runat="server" />
<div class="text-center">
<!-- remove CommandArgument and CommandName from the Delete button. They are useless in the popup. -->
<!-- add an event handler to OnClick-->
<asp:Button ID="Delete" CssClass="btn btn-danger border-2 border-dark" runat="server" Text="Delete" OnClick="BtnDelete_Click" />
...
Create event handlers for when the modal is opened in order to propagate the productId from the current row in the grid to the modal:
<script src="../Scripts/Site.js"></script>
<script type="text/javascript">
$(document).ready(
function () {
//use a jquery selector to assign an event handler to all Delete Buttons found on the page (nottice they all start with the same prexif)
$("[id*=MainContent_GridView_BtnDelete]").click(function () {
//get the id of the product from the selected row first cell and assign it to the hidden field in the modal
$("#MainContent_productIdToDelete").val($(this).closest('tr').find('td').eq(0).html());
});
});
</script>
Finally, handle the delete event in the code behind:
protected void BtnDelete_Click(object sender, EventArgs e)
{
string idVal = Request.Form[productIdToDelete.UniqueID];
var id = Convert.ToInt64(idVal);
// implement delete logic ...
}
Use the same approach for Edit. (Look at this example.)
I am working with a ListView with multiple items listed, each with their own buy button. Right now the user can select the buy button on the item (car) they want, and it takes them to the BuyCars.aspx page, but nothing shows up for the selected item (car). I'm having trouble figuring out how to send the data when the user clicks buy on a certain car to the BuyCars.aspx total page.
I apologize for the amount of code, but this issue is driving me insane.
Here is my code. Thank you!
Cars.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/MasterBlaster024.Master" AutoEventWireup="True" CodeBehind="Cars.aspx.cs" Inherits="CarSales_REAL.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="div2" runat="server">
<div class="row">
<asp:ListView ID="ListView1" runat="server" class="custom-class" DataSourceID="SqlDataSource1" OnItemCommand="ListView1_ItemCommand" DataKeyNames="CarID" OnSelectedIndexChanged="ListView1_SelectedIndexChanged">
<ItemTemplate>
<div class="col-sm-4">
<div class="custom_class">
<a href='/Shop/Order/<%# Eval("CarID") %>'>
<img src='/Images/<%# Eval("ImageCar") %>'
alt='<%# Eval("Name") %>' /></a>
<div class="caption">
<h3>
<%# Eval("Name") %>
</h3>
<p><b>Price: <%# Eval("CarPrice", "{0:c}") %></b>
<br><br>
<%# Eval("Long_Description") %>
</p>
</div>
<%--<div class="row">
<div class ="form-group">
<label class="col-sm-1">Quantity:</label>
</div>
</div>--%>
<div class="col-sm-8">
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="text-danger"
runat="server" ControlToValidate="txtQuantity1" Display="Dynamic"
ErrorMessage="Quantity is a required field." ValidationGroup='<%# ListView1.ClientID + "_" + Container.DataItemIndex %>'></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" CssClass="text-danger" ControlToValidate="txtQuantity1" Display="Dynamic" ErrorMessage="Quantity must range from 1 to 2." MaximumValue="2" MinimumValue="1" Type="Integer"></asp:RangeValidator>--%>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="col-sm-12">
<asp:Button ID="btnBuy" runat="server" Text="Buy Car" onclick="btnAdd_Click" CssClass="btn" ValidationGroup='<%# ListView1.ClientID + "_" + Container.DataItemIndex %>' />
<asp:Button ID="btnCart" runat="server" Text="See Selected Car" PostBackUrl="~/BuyCars.aspx" CausesValidation="False" CssClass="btn" />
</div>
</div>
</div>
<div>
<asp:Label ID="lblMessage" runat="server" EnableViewState="false" CssClass="text-info col-sm-12"></asp:Label>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
<%--<div class="col-sm-3">
<asp:TextBox ID="txtQuantity1" runat="server"
CssClass="form-control"></asp:TextBox>
</div>--%>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [CarID], [Name], [Long_Description], [CarPrice], [ImageCar] FROM [Table] ORDER BY [Name]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
</asp:Content>
Cars.aspx.cs
namespace CarSales_REAL
{
public partial class WebForm2 : System.Web.UI.Page
{
private Product selectedProduct;
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
if (!IsPostBack) ListView1.DataBind();
selectedProduct = this.GetSelectedProduct();
}
private Product GetSelectedProduct()
{
DataView productsTable = (DataView)
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
//productsTable.RowFilter = "CarID = '" + ListView1.SelectedValue + "'";
DataRowView row = productsTable[1];
Product p = new Product();
p.CardID = row["CarID"].ToString();
p.Name = row["Name"].ToString();
//p.Short_Description = row["Short_Description"].ToString();
p.Long_description = row["long_Description"].ToString();
p.CarPrice = (decimal)row["CarPrice"];
//p.ImageFile = row["ImageFile"].ToString();
return p;
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Button btnBuy = (Button)sender;
if (Page.IsValid)
{
CartItemList cart = CartItemList.GetCart();
CartItem cartItem = cart[selectedProduct.CardID];
if (cartItem == null)
{
//cart.AddItem(selectedProduct,
// Convert.ToInt32(txtQuantity1.Text));
}
else
{
//cartItem.AddQuantity(Convert.ToInt32(txtQuantity1.Text));
}
Response.Redirect("BuyCars.aspx");
}
}
protected void btnCart_Click(object sender, EventArgs e)
{
}
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
}
}
}
BuyCars.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/MasterBlaster024.Master" AutoEventWireup="True" CodeBehind="BuyCars.aspx.cs" Inherits="CarSales_REAL.WebForm3" %>
<%# MasterType VirtualPath="~/MasterBlaster024.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="div2" runat="server">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<div class="col-sm-12"><asp:ListBox ID="Cart1" runat="server" CssClass="form-control"></asp:ListBox></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12"><asp:Button ID="btnRemove" runat="server"
Text="Remove Item" OnClick="btnRemove_Click" CssClass="btn"/></div>
<div class="form-group">
<div class="col-sm-12"><asp:Button ID="btnEmpty" runat="server"
Text="Empty Cart" OnClick="btnEmpty_Click" CssClass="btn" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<asp:Label ID="lblMessage" runat="server" EnableViewState="false"
CssClass="text-info col-sm-12"></asp:Label>
</div>
<div class="form-group">
<div class="col-sm-12">
<asp:Button ID="btnContinue" runat="server"
PostBackUrl="~/Cars.aspx" Text="Continue Shopping" CssClass="btn" />
<asp:Button ID="btnCheckOut" runat="server" Text="Check Out"
onclick="btnCheckOut_Click" CssClass="btn" />
</div>
</div>
</div>
</div>
</div>
</asp:Content>
BuyCars.aspx.cs
namespace CarSales_REAL
{
public partial class WebForm3 : System.Web.UI.Page
{
private CartItemList cart;
protected void Page_Load(object sender, EventArgs e)
{
cart = CartItemList.GetCart();
if (!IsPostBack)
this.DisplayCart();
}
private void DisplayCart()
{
Cart1.Items.Clear();
CartItem item;
for (int i = 0; i < cart.Count; i++)
{
item = cart[i];
Cart1.Items.Add(item.Display());
}
}
protected void btnRemove_Click(object sender, EventArgs e)
{
if (cart.Count > 0)
{
if (Cart1.SelectedIndex > -1)
{
cart.RemoveAt(Cart1.SelectedIndex);
this.DisplayCart();
}
else
{
lblMessage.Text = "Please select the item you want to remove.";
}
}
}
protected void btnEmpty_Click(object sender, EventArgs e)
{
if (cart.Count > 0)
{
cart.Clear();
Cart1.Items.Clear();
}
}
protected void btnCheckOut_Click(object sender, EventArgs e)
{
lblMessage.Text = "Sorry, that function hasn't been implemented yet.";
}
}
}
I am having an issue with my "save" linkbutton firing and am at a loss. I have included the code for the form and code-behind. I have added some testing to see if the event is firing and it doesn't appear to be so. Any help is appreciated. I am a novice coder so excuse me if there are obvious issues or a better way to proceed. Ultimate goal is to update the entry in the database for the given screen info and then redisplay to updated info.
Again thank you in advance.
UPDATE: I have included the FULL-ish CODE: (removed the sensitive info)
CODEBEHIND:
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class matter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
...
}
protected void fvdoc_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
throw new Exception("Clicked");
}
throw new Exception("i've been Clicked");
}
}
PAGE:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="matter.aspx.cs" Inherits="matter" %>
<!DOCTYPE html>
<html>
<head>
<title>Wasatch Client Matter Index</title>
<link rel="shortcut icon" href="~/favicon.ico" type="image/x-icon" />
<meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1, user-scalable=no"/>
<!-- Latest compiled and minified CSS -->
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Ubuntu+Condensed' type='text/css' />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous" />
<link rel="stylesheet" href="Content/themes/Site.css" />
<!-- Latest compiled JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"/>
</head>
<body>
<div class="navbar">
<div class="row">
<h1 class="col-lg-8 col-lg-offset-2 text-center " style="align-content:center;">Matter Index </h1>
</div>
</div>
<div class="container-fluid">
<form id="form1" runat="server">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 form-group">
<asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
<ItemTemplate>
<h2 class="col-md-12"><asp:Label ID="tbname" runat="server" Text=<%# Bind("docid") %> /> - <asp:Label ID="lbID" runat="server" Text=<%# Bind("sName") %> /></h2>
<div class="left col-md-10">
<legend>Matter Info:</legend>
<div class="form-group"><asp:Label runat="server" Text="Matter" AssociatedControlID="dcname"/>
<asp:TextBox ID="dcname" runat="server" CssClass="form-control" Text=<%# DataBinder.Eval(Container.DataItem,"sDocname") %> Enabled="true"/></div>
</div>
<div class="left col-md-10">
<hr />
<div class="form-group"><asp:Label runat="server" Text="Notes/Comments" AssociatedControlID="dcnotes" />
<asp:TextBox ID="dcnotes" runat="server" Rows="3" TextMode="MultiLine" Text=<%# Bind("sdocdesc") %> Enabled="true"/></div>
</div>
<div class="left col-md-6 col-md-offset-5 txsmall">
<asp:Label runat="server" Text="Filed: " Font-Bold="true" /><asp:Label ID="lblfiledate" runat="server" Text=<%# Bind("dtFiledate") %> CssClass="txsmall" Font-Italic="true" />
<asp:Label runat="server" Text="Modified: " Font-Bold="true" /><asp:Label ID="lblmodify" runat="server" Text=<%# Bind("dtLastModified") + " - " + Bind("susermodified") %> CssClass="txsmall" Font-Italic="true"/>
<asp:Label runat="server" CssClass="txsmall" id="lbltest"/>
</div>
<div class="clear-fix col-md-12">
<div class="form-group">
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
<asp:LinkButton runat="server" Text="Move" ID="MoveButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="m.aspx" />
<asp:LinkButton runat="server" Text="Home" ID="HomeButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="default.aspx"/>
</div>
</div>
</ItemTemplate>
</asp:FormView>
</div>
</div>
<hr class="col-lg-10 col-lg-offset-1" />
</form>
</div>
...
</body>
</html>
Your link button is present inside a formview item template as can be seen below and thus you will not get the individual control event (onclick event of linkbutton). Rather you need to handle the FormView.ItemCommand and do your processing like
<asp:FormView ID="fvdoc" runat="server"
DataSourceID="gvdb" onitemcommand="itemCommandClick">
<ItemTemplate>
.......
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" .........
In code behind handle this like
void itemCommandClick(Object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
LinkButton button = e.CommandSource as LinkButton;
//Do rest of the processing
}
}
Your FormView is missing the EditItemTemplate, like so:
<asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
<ItemTemplate>
<!--... Use readonly controls like Label etc...-->
<asp:LinkButton runat="server" Text="Save" ID="EditButton" CommandName="Edit" CssClass="clear-fix btn btn-primary" />
</ItemTemplate>
<EditItemTemplate>
<!--... Use editable controls like TextBox etc...-->
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
</EditItemTemplate>
</asp:FormView>
For the click on the Edit Button, change to Edit mode, then Handle the Save button to save the new values.
See the MSDN docs for more information.
I want to show the selected items once i click outside of the drodowncombobox(Radcombobox). Which event shall i call to perform it?
Here is my code:
private static void ShowCheckedItems(RadComboBox comboBox, Literal literal)
{
var sb = new StringBuilder();
var collection = comboBox.CheckedItems;
if ( collection.Count != 0 )
{
sb.Append("<h3>Checked Items:</h3><ul class=\"results\">");
foreach ( var item in collection )
sb.Append("<li>" + item.Text + "</li>");
sb.Append( "</ul>" );
literal.Text = sb.ToString();
}
else
{
literal.Text = "<p>No items selected</p>";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ShowCheckedItems(RadComboBox1, itemsClientSide);
}
In the above code, the action is executed based on a button click. But i want to show the same effect on clicking outside of the RadComboBox1.
Here is the html code:
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
</Scripts>
</telerik:RadScriptManager>
<%--<telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />--%>
<telerik:RadFormDecorator ID="FormDecorator1" runat="server" Skin="Metro" />
<div class="qsf-demo-canvas">
<div class="continents">
<telerik:RadComboBox ID="RadComboBox1" runat="server" Width="186px"
AutoPostBack="true" EmptyMessage="- Select a Country -"
OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"
Skin="Metro">
</telerik:RadComboBox>
</div>
<div class="countries">
<telerik:RadComboBox ID="RadComboBox2" runat="server" Width="186px"
AutoPostBack="true" EmptyMessage="- Select a City -"
CheckBoxes="true"
EnableCheckAllItemsCheckBox="true"
Skin="Metro">
</telerik:RadComboBox>
</div>
<p class="buttons">
<asp:Button ID="Button1" runat="server" Text="Explore" OnClick="Button1_Click" />
</p>
<div class="result">
<asp:Literal ID="itemsClientSide" runat="server" />
</div>
</div>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadComboBox1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadComboBox2" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
<script type="text/javascript">
//Put your JavaScript code here.
</script>
<div>
</div>
</form>
Thanks!
There is a jQuery Dialog with a GridView inside it in my aspx page. also have a button as Save on jQuery Dialog. I need to get values in GridView after click on this button in C#. I have tried as below. But not worked. I changed value in TextBox and click Save button. But it is not gave me edited value. nothing returned.
ASPX Page
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
/* Java scripts and style sheets are here */
<script type="text/javascript">
function showDialog() {
$('#dialogDiv').dialog('open');
}
$(document).ready(function () {
$('#dialogDiv').dialog({
autoOpen: false,
resizable: true,
width: 300,
height: 'auto',
buttons: {
"Save": function () {
$('#' + '<%= btnSaveType.ClientID %>').trigger("click");
}
}
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div id="dialogDiv" title="Type" style="overflow: hidden">
<div id="TypeDiv" class="divTable">
<div class="divRow">
<div class="divColumn">
<div>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="open" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="Type_GV" runat="server" ShowFooter="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:TextBox ID="txtType" runat="server" Text='<%# Bind("Type") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</div>
<asp:Button ID="open" runat="server" Text="Open dialog" OnClick="open_Clicked" OnClientClick="showDialog()" />
<br />
<p>
<asp:Button ID="btnSaveType" runat="server" OnClick="btnSaveType_Clicked" Style="visibility: hidden;
display: none;" />
</p>
</asp:Content>
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
}
protected void open_Clicked(object sender, EventArgs e)
{
VehicleType vTypeObject = new VehicleType();
Type_GV.DataSource = vTypeObject.GetTypeList();
Type_GV.DataBind();
}
protected void btnSaveType_Clicked(object sender, EventArgs e)
{
foreach (GridViewRow gvr in Type_GV.Rows)
{
TextBox type = (TextBox)gvr.FindControl("txtType");
Debug.WriteLine("type : " + type.Text);
// when debug, print as type :
// nothing print for type.Text
}
}
}
public class VehicleType
{
public string Type { get; set; }
public List<VehicleType> GetTypeList()
{
List<VehicleType> list = new List<VehicleType>()
{
new VehicleType{Type="Type1"}
};
return list;
}
}
How can i solve this ?