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.
Related
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
I have been searching the web for hours trying to figure out what is causing this exception, I feel like I am missing something...
<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" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" CellPadding="3" DataKeyNames="ProductID"
DataSourceID="SqlDataSource1"
GridLines="Vertical">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
SortExpression="CategoryID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title"
/>
<asp:BoundField DataField="ShortDescription" HeaderText="ShortDescription"
SortExpression="ShortDescription" />
<asp:BoundField DataField="LongDescription" HeaderText="LongDescription"
SortExpression="LongDescription" />
<asp:BoundField DataField="ImageUrl" HeaderText="ImageUrl"
SortExpression="ImageUrl" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price"
/>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="Title" DataValueField="CategoryID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:s3435926ConnectionString %>"
SelectCommand="SELECT [CategoryID], [Title] FROM [Category]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:s3435926ConnectionString %>"
SelectCommand="SelectProductsWithParam" SelectCommandType="StoredProcedure"
UpdateCommand="UpdateProdsWithParam" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:FormParameter FormField="DropDownList1" Name="prodID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="prodID" Type="Int32" />
<asp:Parameter Name="CatID" Type="Int32" />
<asp:Parameter Name="title" Type="String" />
<asp:Parameter Name="Sdesc" Type="String" />
<asp:Parameter Name="Ldesc" Type="String" />
<asp:Parameter Name="url" Type="String" />
<asp:Parameter Name="price" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
The SP is
[dbo].[UpdateProdsWithParam] #prodID int, #CatID int, #title nvarchar(50),
#Sdesc nvarchar(100), #Ldesc nvarchar(200),
#url nvarchar(50), #price money
AS
UPDATE Product
SET CategoryID = #CatID, Title = #title,
ShortDescription = #Sdesc, LongDescription = #Ldesc,
ImageUrl = #url, Price = #price
WHERE ProductID = #prodID
I am getting 'Procedure or Function has too many parameters specified'
Any suggestions?
Share your C# code. Error clearly says that you are passing too many parameters. Check out your parameters count & parameters name.
I've created a page that spits out data from a table. I've gotten the update and delete functionality, but I'm having trouble figuring out how to search and add values. I threw in a few text boxes to mess around with, but I don't know how to make them into controls. I'd like to be able to search the data, as well as enter new data. How do I make these text boxes into search controls for the grid? Also how do I use text boxes or drop down boxes to insert new values into the table?
Here is what I have so far:
<%# Page Title="Bank Statements" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BankStatements.aspx.vb" Inherits="Compliance.BankStatements" %>
<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
</script>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<hgroup class="title">
<h1><%: Title %>.</h1>
<h2>Enter View and Edit Bank Statments Here<br />
</h2>
</hgroup>
<br />
Franchise ID:
<asp:TextBox ID="TextBox1" runat="server" Width="95px"></asp:TextBox>
Year:
<asp:TextBox ID="TextBox2" runat="server" Width="56px"></asp:TextBox>
Month:
<asp:TextBox ID="TextBox3" runat="server" Width="65px"></asp:TextBox>
<asp:GridView
ID="GridView1"
runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display."
ForeColor="#333333"
GridLines="None"
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
EnableSortingAndPagingCallbacks="True"
AllowPaging="True"
>
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="FranchiseID" HeaderText="FranchiseID" SortExpression="FranchiseID" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Month" HeaderText="Month" SortExpression="Month" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
<asp:BoundField DataField="DatePosted" HeaderText="DatePosted" SortExpression="DatePosted" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<hgroup>
</hgroup>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ComplianceConnectionString1 %>"
SelectCommand=
"SELECT FranchiseID, Year, Month, Amount, DatePosted, id FROM BankStmts ORDER BY DatePosted DESC"
DeleteCommand=
"DELETE
FROM [BankStmts]
WHERE id = #id"
UpdateCommand=
"UPDATE [BankStmts]
SET FranchiseID = #FranchiseID, Year = #Year, Month = #Month, Amount = #Amount, DatePosted = #DatePosted
WHERE id = #id"
InsertCommand=
"Insert INTO [BankStmts] FranchiseID, Year, Month, Amount, DatePosted
VALUES #FranchiseID, #Year, #Month, #Amount, #DatePosted"
>
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FranchiseID" />
<asp:Parameter Name="Year" />
<asp:Parameter Name="Month" />
<asp:Parameter Name="Amount" />
<asp:Parameter Name="DatePosted" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FranchiseID" />
<asp:Parameter Name="Year" />
<asp:Parameter Name="Month" />
<asp:Parameter Name="Amount" />
<asp:Parameter Name="DatePosted" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
can someone plz tell me how to show data in gridview without postback when i enter some text in textbox .... i mean onkeyup event without postback
with postback i am able to do the same in asp.net using C#...
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function runPostback() {
document.forms["form1"].submit();
document.getElementById("TextBox1").focus();
}
function SetDelay() {
setTimeout("runPostback()", 100);
}
</script>
<style type="text/css">
.style1
{
width: 100%;
}
FixedHeader {
position: absolute;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<%--<asp:TextBox ID="TextBox1" runat="server"
onkeyup="javascript:_doPostBack('TextBob1',' ')" onfocus="this.value = this.value;"
AutoPostBack="true" ontextchanged="TextBox1_TextChanged" ></asp:TextBox>
<br />
--%>
<asp:UpdatePanel ID="gridsearchUpdatePanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TextBox1" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="TextBox1" onkeyup="SetDelay();" runat="server" Width="490px"></asp:TextBox>
<div id="gridDiv" style="max-height:190px; overflow:auto; max-width:495px; ">
<asp:GridView ID="SearchGridView" runat="server" AutoGenerateColumns="False"
HeaderStyle-CssClass="FixedHeader" HeaderStyle-BackColor="YellowGreen"
DataSourceID="SearchMembersSqlDataSource" Width="476px" CellPadding="3"
GridLines="Horizontal" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" ShowHeader="False" >
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="vname" HeaderText="vname" SortExpression="vname" />
<asp:BoundField DataField="vemail" HeaderText="vemail"
SortExpression="vemail" />
<asp:BoundField DataField="vpassword" HeaderText="vpassword"
SortExpression="vpassword" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7"
Wrap="True" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
</div>
<asp:SqlDataSource ID="SearchMembersSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:DemoDBConnectionString %>"
SelectCommand="prcAdvanceSearchUser" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="username" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Is there any way of doing it without postback ???
You can try changing the display style of the DIV layer which is holding the GridView.
Modify the TextBox
<asp:TextBox ID="TextBox1" onkeyup="OnKeyUp_TextBox();" runat="server" Width="490px"></asp:TextBox>
Also the script function to be called
function OnKeyUp_TextBox() {
var oGridDIV = document.getElementById("gridDiv");
if(oGridDIV != null) {
oGridDIV.display = "block"; // display the DIV layer with gridview
// oGridDIV.display = "none"; // hide the DIV layer with gridview
}
}
ANd finally the style of the DIV layer holding the GridView
<div id="gridDiv" style="max-height:190px; overflow:auto; max-width:495px; display:none;">
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>