Using cookies in Select Query - asp.net

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

Related

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 select an option from a dropdown list in one webform and view the result in a gridview in another webform?

this is my project, i am using visual studio 2010 and my coding language is vb. I am new to this and it will be safe to say that i don't know much of it yet.
I have a login page where the head of department enters his detail(employee number, employee name), selects his department and submits the information to see the result in other web form i.e all the employees that are under his department out of all the employees working for the company.
Because i don't know the code, i am getting all the employees of every department in the gridview instead of getting the employees for the department that was selected from the dropdown list.
here is my code for the first page
<%# Page Language="VB" AutoEventWireup="false" CodeFile="login.aspx.vb" Inherits="login" %>
<!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>
<style type="text/css">
.style1
{
width: 1179px;
height: 106px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<img alt="iocl" class="style1" src="Images/materials_hrd.bmp" /><br />
<br />
<br />
<br />
</div>
<asp:Label ID="Label1" runat="server" Text="Employee Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Employee_Number" runat="server" Text="Employee Number"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
-<br />
<asp:Label ID="Label2" runat="server" Text="Department"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Information Systems</asp:ListItem>
<asp:ListItem>Human Resources</asp:ListItem>
<asp:ListItem>Resource & Development</asp:ListItem>
<asp:ListItem>Finance</asp:ListItem>
<asp:ListItem>Pipelines</asp:ListItem>
<asp:ListItem>Marketing</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
</form>
</body>
</html>
And this is the second page's code
<%# Page Language="VB" AutoEventWireup="false" CodeFile="HODLogin.aspx.vb" Inherits="HODLogin" %>
<!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>
<style type="text/css">
.style1
{
width: 1259px;
height: 105px;
margin-top: 0px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<img alt="iocl" class="style1" src="Images/materials_hrd.bmp" /><br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" Height="195px" ShowHeaderWhenEmpty="True"
Width="1125px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Employee Number" HeaderText="Employee Number"
SortExpression="Employee Number" />
<asp:BoundField DataField="Employee Name" HeaderText="Employee Name"
SortExpression="Employee Name" />
<asp:BoundField DataField="Department" HeaderText="Department"
SortExpression="Department" />
<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString11 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString11.ProviderName %>"
SelectCommand="SELECT * FROM [employee database]"></asp:SqlDataSource>
<br />
<asp:Label ID="lblempno" runat="server"
Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Please tell me the process and the code and also where to put it, i am not very familiar with all this. Its kind of an emergency.
You can just store the selected item text in onw variable, like the below:
dim selText as string = DropDownList1.SelectedItem.Text
and on the click of submit button, perform your required tasks and then redirect page to another page along with the department name. Like the below code:
Response.Redirect("Page2.aspx?department=" + selText)
and on the second page i.e. Page2.aspx, just receive this value in query string, using below code.. wherever it is necessary either on page load or at your required place.
If Request.QueryString("department") <> Nothing Then
dim departmt as string = Request.QueryString("department")
End If
And use the above variable's value in your database query and get the related data to the department selected in the previous form.
I hope it will help you. :)
You can also save selected item text in Session. Afterward you can get this value from any page in your project:
Session("department") = DropDownList1.SelectedItem.Text
You also can use this value directly in your SqlDataSource on Page2:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString11 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString11.ProviderName %>"
SelectCommand="SELECT * FROM [employee database] WHERE Department LIKE #depart">
<SelectParameters>
<asp:SessionParameter DefaultValue="%" Name="depart" SessionField="user"
Type="string" />
</SelectParameters>
</asp:SqlDataSource>

Gridview inside web user control not visible in design view after using update panel

I created a web user control & placed a gridview inside an update panel. I added this control to my webform but I cannot see the grid inside design view. I just see controls which are outside the update panel. Everything works fine when I view it in browser or remove update panel from the user control.
Is there someway to show my grid? Its confusing to see a blank space instead of the grid control in design view.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl.aspx.cs" Inherits="TestWebsite.WebUserControl" %>
<%# Register src="Controls/Products.ascx" tagname="Products" tagprefix="uc1" %>
<!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>
<uc1:Products ID="Products1" runat="server" />
</div>
</form>
</body>
</html>
Product.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Products.ascx.cs" Inherits="TestWebsite.Controls.Products" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upnlProducts" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="SqlDataSource1">
<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:BoundField DataField="CategoryName" HeaderText="CategoryName"
SortExpression="CategoryName" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Alphabetical list of products]">
</asp:SqlDataSource>
<br />

Insert and Delete Query stopped working in AccessDataSource

I have a submit button that inserts user entered data into a database. It was working perfectly fine until I migrated the project to the host server. The select query is still functional and displaying my data in the GridView (I checked by manually inserting some data into the database on the host server), I am unable to insert or delete data via the client-side page. It's an access database and I am connecting to it using the Visual Studio AccessDataSource.
Also, I don't receive any errors when loading the page or when I hit submit, its just that nothing happens.
Here is my code:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="jotest.aspx.vb" Inherits="jotest" %>
<!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>
<script language="javascript" type="text/javascript">
<!--
function imposeMaxLength(Object, MaxLen) {
return (Object.value.length <= MaxLen);
}
-->
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/login.mdb"
DeleteCommand="DELETE FROM tblComments WHERE ID = #ID"
InsertCommand="INSERT INTO tblComments(comment, commentor_name, comment_date) VALUES (#comment, #commentor_name, #comment_date)"
SelectCommand="SELECT ID, commentor_name, comment, comment_date FROM tblComments">
<InsertParameters>
<asp:Parameter Name="commentor_name" />
<asp:Parameter Name="comment" />
<asp:Parameter Name="comment_date" />
<asp:Parameter Name="ID" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="ID" />
</DeleteParameters>
</asp:AccessDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="position: absolute; top: 50px; left: 600px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="comment" HeaderText="Name" SortExpression="comment" ItemStyle-Width="80px" />
<asp:BoundField DataField="commentor_name" HeaderText="Comment" SortExpression="commentor_name" ItemStyle-Width="300px" />
<asp:BoundField DataField="comment_date" HeaderText="Date" SortExpression="date" ItemStyle-Width="175px" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
<br />
<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Name:<asp:TextBox ID="commentor_nameTextBox" runat="server" Text='<%# Bind("commentor_name") %>'></asp:TextBox>
<br />
Comment:<asp:TextBox ID="txtComments" runat="server" onkeypress="return imposeMaxLength(this, 150);" Text='<%# Bind("comment") %>' TextMode="MultiLine" Rows="4" Columns="50"></asp:TextBox>
<br />
<asp:HiddenField ID="hidTimeDate" runat="server" Value='<%# Bind("comment_date") %>' />
<asp:Button ID="butSubmit" runat="server" CommandName="Insert" Text="Submit" />
</InsertItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Make sure the account that is accessing the file has read and write access on the host server folder where the mdb file is located.

How to value set on TextBox

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]

Resources