How to value set on TextBox - asp.net

Work on Asp.Net C# VS08.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var styleToSelect;
function onOk() {
document.getElementById('GridView1').className = styleToSelect;
}
</script>
<script language="javascript" type="text/javascript">
function GetRowValue(val) {
// alert(val);
document.getElementById("Text1").value = val;
// hardcoded value used to minimize the code.
// ControlID can instead be passed as query string to the popup window
//window.opener.document.getElementById("ctl00_ContentPlaceHolder2_GridView1_txtCOM_NAME").value = val;
//window.opener.document.getElementById('%=txtCOM_NAME.ClientId%>').value = val;
//window.opener.document.getElementById("txtParent").value = val;
//Text1.innerHTML=val;
// alert(val);
// window.close();
}
function Hello()
{
document.getElementById("Text1").value="2";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:LinkButton ID="LinkButton1" runat="server">Please click to select an alternate text style.</asp:LinkButton><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1">
<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" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="Button2"
PopupControlID="Panel2"
BackgroundCssClass="modalBackground"
DropShadow="true"
OkControlID="OkButton"
CancelControlID="CancelButton"
OnOkScript="onOk()"
/>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px" CssClass="modalPopup">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="ckb">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
<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" />
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button3" runat="server" Text="Button" />
<div align="center">
<asp:Button ID="OkButton" runat="server" Text="OK" OnClick="OkButton_Click" OnClientClick=Hello() />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
<input id="Button4" type="button" value="button" /></div>
</asp:Panel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
After Popup .Want to select a row on popup grid then click on ok button and put the value on TextBox fo the parent grid.How to set value on Parent Grid.

I guess you should use the row command event handler of the grid, if I got you right:
OnRowCommand="RowCommand"
Then you can add a button to the grid:
<asp:LinkButton ID="LnkButton" runat="server" CommandName="setValue" CommandArgument='<%# Eval("id")%>'>Set value</asp:LinkButton>
And a method to handle it:
protected void RowCommand(Object sender, GridViewCommandEventArgs e)
if (e.CommandName=="setValue")
[do something with e.CommandArgument and close dialog]

Related

Using cookies in Select Query

So, I have a select query where I am taking the value selected from a drop down list on one page and using that in SELECT queries for others. The issue I am having is that when I navigate from one page to the next, the cookie is not used in the query. If anyone can figure out why, that'd be great.
My code for both pages is below:
Homepage
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductName] FROM [Products]"></asp:SqlDataSource>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductName">
</asp:DropDownList>
<br />
<br />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/infopage.aspx">Information Screen</asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="~/Orders.aspx">Orders Screen</asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton3" runat="server" PostBackUrl="~/Items.aspx">Items Screen</asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton4" runat="server" PostBackUrl="~/Totals.aspx">Total Screen</asp:LinkButton>
</div>
</form>
</body>
</html>
First linked page:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="infopage.aspx.vb" Inherits="infopage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [Discontinued], [ReorderLevel] FROM [Products] WHERE [ProductName] = #p1">
<SelectParameters>
<asp:CookieParameter CookieName="product" Name="p1" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="None" Height="50px" Width="125px">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<Fields>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
<asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
</Fields>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
</asp:DetailsView>
<br />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Default.aspx">Go back</asp:LinkButton>
<br />
<br />
</div>
</form>
</body>
</html>
Code-behind for homepage:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
Dim product As New HttpCookie("product")
product.Value = DropDownList1.SelectedValue
product.Expires = DateTime.Now.AddHours(1)
Response.Cookies.Add(product)
End Sub
End Class

How can i fire an event upon clicking the image items inside a data list?

I am a beginner in Asp.Net. I have a datalist populated with images. What i want is to know what image was clicked so that I can redirect the user to a different page as per the image clicked inside the datalist.
Here is my source:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MediaCenter.aspx.vb" Inherits="Default2" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Categories<br />
<br />
<br />
<asp:DataList ID="dtlCat" runat="server" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center" OnItemCommand="CatSelect" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server"
Text='<%# Eval("FolderName") %>' />
<br />
<img src="<%# ResolveUrl(String.Format("~/img/apple-touch-icon-114x114.png", Container.DataItem)) %>" onclick="cat_select" />
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
I've given comments inside the code to explain how it works.
Your HTML Designer :
<asp:datalist id="DataList1" runat="server" onitemcommand="dtlCat_ItemCommand" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server" Text='<%# Eval("FolderName") %>' />
<br />
<%--Here the "ImageID" is the Id coming from your Database--%>
<asp:ImageButton ID="ImgBtnViewInq" runat="server" ImageUrl="~/images/Viewmail.png" CommandName="View" CommandArgument='<%# Eval("ImageID") %>' ToolTip="View" />
<%--You can do the same from your link button here too the "ImageID" is the Id coming from your Database--%>
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" CommandArgument='<%# Eval("ImageID") %>' ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:datalist>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
C# Code Behind :
protected void dtlCat_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "View")
{
// Here "i" will get the imageid(CommandArgument='<%# Eval("ImageID") %>') that was given inside the image button tag
int i = Convert.ToInt32(e.CommandArgument);
Response.Redirect("YourPage.aspx?clickedimgID=" + i);
}
if (e.CommandName == "show")
{
// Here "i" will get the imageid (CommandArgument='<%# Eval("ImageID") %>') that was given inside the Link button tag
int i = Convert.ToInt32(e.CommandArgument);
Response.Redirect("YourPage.aspx?clickedimgID=" + i);
}
}
Hope that helps
Try this
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MediaCenter.aspx.vb"
Inherits="Default2" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.11.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Categories<br />
<br />
<br />
<asp:DataList ID="dtlCat" runat="server" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server"
Text='<%# Eval("FolderName") %>' />
<br />
<img src="<%# ResolveUrl(String.Format("~/img/apple-touch-icon-114x114.png", Container.DataItem)) %>"/>
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Hope this may helps you. Let me Know if it helps you.

How to make Sorting Gridview - header a hyperlink (clickable)

I was using this file as a reference
http://code.msdn.microsoft.com/VBASPNETGridView-19039173
I would like to follow the sorting function in that demo.
But when I build a simple page . my gridview header is not a hyperlink
I already have sortExpression. but the header stays as regular text (not clickable).
This is the ASPX of my TEST aspx.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplicationSandBox.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="PersonID" HeaderText="PersonID" ReadOnly="False" SortExpression="PersonID" />
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
This is the ASPX file from the demo file. Could you please help me point out which
properties makes the gridview header a hyperlink (clickable)? Thank you
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="DataInMemory.aspx.vb" Inherits="VBASPNETGridView.DataInMemory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvPerson" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
onpageindexchanging="gvPerson_PageIndexChanging"
onrowcancelingedit="gvPerson_RowCancelingEdit"
onrowdatabound="gvPerson_RowDataBound" onrowdeleting="gvPerson_RowDeleting"
onrowediting="gvPerson_RowEditing" onrowupdating="gvPerson_RowUpdating"
onsorting="gvPerson_Sorting">
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="PersonID" HeaderText="PersonID" ReadOnly="False"
SortExpression="PersonID" />
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>
<br />
<asp:LinkButton ID="lbtnAdd" runat="server" onclick="lbtnAdd_Click">AddNew</asp:LinkButton>
<br />
<br />
<asp:Panel ID="pnlAdd" runat="server" Visible="False">
Last name:
<asp:TextBox ID="tbLastName" runat="server"></asp:TextBox>
<br />
<br />
First name:
<asp:TextBox ID="tbFirstName" runat="server"></asp:TextBox>
<br />
<br />
<asp:LinkButton ID="lbtnSubmit" runat="server" onclick="lbtnSubmit_Click">Submit</asp:LinkButton>
<asp:LinkButton ID="lbtnCancel" runat="server" onclick="lbtnCancel_Click">Cancel</asp:LinkButton>
</asp:Panel>
</div>
</form>
</body>
</html>
When i use this code it displays the Header as links - is that what your after?
<asp:GridView ID="GridView1" runat="server" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" AllowSorting="true">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="PersonID" HeaderText="PersonID" ReadOnly="False" SortExpression="PersonID" />
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Gridview is made sortable with the AllowSorting property:
<asp:GridView ID="GridView1"
runat="server"
-->AllowPaging="True" <--
AllowSorting="True" >
<Columns>
{insert your columns}
</Columns>
</asp:GridView>
That will make your headers clickable. The sample page didn't set AllowSorting on the control. The code later in the page shows where they set this in code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' The Page is accessed for the first time.
If Not IsPostBack Then
' Enable the GridView paging option and
' specify the page size.
gvPerson.AllowPaging = True
gvPerson.PageSize = 15
' Enable the GridView sorting option.
--> gvPerson.AllowSorting = True <--
' Initialize the sorting expression.
ViewState("SortExpression") = "PersonID ASC"
' Populate the GridView.
BindGridView()
End If
End Sub
Hope that helps. :)

How do i get asp:Panel Default Button to fire button click event?

I have three asp net text boxes that will contain search criteria for searching a table. I would like the search to work like Google. When the enter key is pressed to have the click event on the "Enter" button fire. The click event never fires. What can I do to get it to fire?
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebCategoryGenerateEdit.ascx.cs"
Inherits="EPPA.Controls.WebCategoryGenerateEdit" ClientIDMode="Static" %>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">
// debugger;
function pageLoad() {
var gvCategoryMessage = $("#<%=GVCategoryMessage.ClientID %>").html
if (gvCategoryMessage.length != 0) {
$("#<%=GVParentCategoryLinkTitle.ClientID %>").keydown(function () {
$("#<%=GVCategoryMessage.ClientID %>").html("");
})
$("#<%=GVCategoryLinkTitle.ClientID %>").keydown(function () {
$("#<%=GVCategoryMessage.ClientID %>").html("");
})
}
}
</script>
<asp:ScriptManager runat="server" />
<asp:MultiView ID="Multiview1" runat="server" ActiveViewIndex="0">
<asp:View ID="SearchView" runat="server">
<asp:Table ID="TableSV1" runat="server">
<asp:TableRow ID="TableRowSV1" runat="server">
<asp:TableCell ID="TableCellSV1" runat="server">
<asp:Label ID="LabelSV1" runat="server" SkinID="SearchTextLabel"
Text="CB or CJ" CssClass="searchTextLabel_Division"/>
</asp:TableCell>
<asp:TableCell ID="TableCellSV2" runat="server">
<asp:Label ID="LabelSV2" runat="server"
SkinID="SearchTextLabel" Text="Parent Category Link Title"
CssClass="searchTextLabel_ParentCategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV3" runat="server">
<asp:Label ID="LabelSV3" runat="server"
SkinID="SearchTextLabel"
Text="Category Link Title" CssClass="searchTextLabel_CategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV4" runat="server">
<asp:Label ID="Label1" runat="server"
SkinID="SearchTextLabel"
Text="Category ID" CssClass="searchTextLabel_CategoryID" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="SVTableRowSV2" runat="server">
<asp:TableCell ID="TableCellSV5" runat="server">
<asp:DropDownList ID="SVDivisionDDL" runat="server"
OnSelectedIndexChanged="SVDivisionDDL_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="CB">CB</asp:ListItem>
<asp:ListItem Value="CJ">CJ</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
<asp:TableCell ID="TableCellSV6" runat="server" >
<asp:panel ID="SVPCLTContainer" runat="server"
DefaultButton="SV6EnterButton">
<asp:TextBox ID="SVParentCategoryLinkTitle" runat="server"
SkinID="SearchTextBox"
CssClass="searchTextBox_ParentCategoryLink" />
<asp:Button ID="SV6EnterButton" runat="server" Visible="false"
Text="Enter" OnClick="EnterKeyPressed_Click" />
</asp:panel>
</asp:TableCell>
<asp:TableCell ID="TableCellSV7" runat="server" >
<asp:TextBox ID="SVCategoryLinkTitle"
runat="server" SkinID="SearchTextBox"
CssClass="searchTextBox_CategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV8" runat="server" >
<asp:TextBox ID="SVCategoryID" runat="server"
SkinID="SearchTextBox"
CssClass="searchTextBox_CategoryID" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button ID="SVGenNewButton" runat="server" Text="Generate New Category ID"
OnClick="SVGenerateNewButton_Click" />
<asp:Button ID="SVDeleteButton" runat="server" Text="Delete Checked items"
OnClick="SVDeleteButton_Click" />
<div style="width:618px; overflow-x:no-display; overflow-y:auto; max-height:392px;
padding-top:2px; ">
<asp:GridView ID="gvWebCategoryID" runat="server" AutoGenerateColumns="False"
SkinID="gridViewSkin" OnRowDeleting="gvWebCategoryID_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="SVgridViewEditButton" runat="server"
OnClick="gvWeCategoryIDEditButton_Click" Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Division" HeaderText="CB or CJ"
Visible="true" />
<asp:BoundField DataField="ParentCategoryLinkTitle" HeaderText="Parent
Category Link Title" />
<asp:BoundField DataField="CategoryLinkTitle" HeaderText="Category
Link Title" />
<asp:BoundField DataField="CategoryID" HeaderText="Category ID" />
<asp:TemplateField HeaderText="Error Message" Visible="false" >
<ItemTemplate>
<asp:Label ID="ErrorMessage" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:View>
</asp:MultiView>
and here is the behind code method:
protected void EnterKeyPressed_Click(object sender, EventArgs e)
{
ReloadData();
this.Multiview1.ActiveViewIndex = 0;
}
At a quick glance, have you tried removing the return false here:
$("#<%=SVParentCategoryLinkTitle.ClientID %>").keydown(function (e) {
if (e.which == 13) {
__doPostBack("#<%=EnterKeyPressed.UniqueID %>", "");
return false;
}
})
check out this question and answer, if it helps: Default button not working in asp.net panel
the DefaultButton is used to capture the Enter key press if the focus is already inside the panel, for example you must have moved the focus to an input field like the text boxes inside the panel. if the focus is not there it won't work.

Display pop-up with simple text upon Button click

I have a button placed on each row of my GridView. When the user presses the button I would like to display a simple popup where I show text. Part of the text is the DataKeyName related to the specific row.
I already tried with ModalPopupExtender myMPE triggered by the button and I used a Panel myPanel as PopupControlID. The problem is that the TextBox txtPanel of the Panel where I place the DataKeyName value is always empty. I tried to debug without myMPE and the txtPanel of the Panel is correctly filled. I guess it makes a mess with the postbacks.
Anybody knows a solution?
Are you doing a manual refresh of the UpdaePanel on the modal popup panel ? If not, try manually refreshing the updatePanel & set its updateMode to Conditional.
Check above example
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="Stylesheet" type="text/css" href="css/StyleSheet.css" />
<style type="text/css">
.modal
{
background-color: Aqua;
width: 150px;
height: 100px;
padding: 6px;
}
.modalBackground
{
background-color: #CCCCFF;
filter: alpha(opacity=40);
opacity: 0.5;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:UpdatePanel ID="upnGrid" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView CssClass=".Grid-blue" ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
<asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
<asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" OnClick="lbEdit_Click">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext"
EntityTypeName="" TableName="Products">
</asp:LinqDataSource>
</div>
<ajaxToolkit:ModalPopupExtender BackgroundCssClass="modalBackground" ID="mpeDetails"
CancelControlID="btnClosePopup" TargetControlID="btnShowModal" PopupControlID="pnlDetails"
runat="server">
</ajaxToolkit:ModalPopupExtender>
<asp:Button ID="btnShowModal" runat="server" Text="Button" Style="display: none" />
<asp:Panel ID="pnlDetails" CssClass="modal" runat="server" Style="display: none">
<asp:UpdatePanel ID="upnDetails" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label>
ID:</label><asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<br />
<label>
Name:</label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
</ContentTemplate>
</asp:UpdatePanel>
<div>
<asp:Button ID="btnClosePopup" runat="server" Text="Cancel" /></div>
</asp:Panel>
</form>
</body>
</html>
.CS
protected void lbEdit_Click(object sender, EventArgs e)
{
LinkButton lbTemp = (LinkButton)sender;
if (lbTemp != null)
{
GridViewRow grow =(GridViewRow) lbTemp.NamingContainer;
int id = Convert.ToInt32(GridView1.DataKeys[grow.RowIndex][0].ToString());
mpeDetails.Show();
txtID.Text = id.ToString();
upnDetails.Update();
}
}

Resources