Querystring value in sqldatasourse - c#

I have the following which works fine:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="test_library_newsletter_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">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family:Arial;">
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="false"
emptydatatext="No data available."
allowpaging="true"
runat="server"
ShowHeader="True"
GridLines="None"
CellPadding="10">
<Columns>
<asp:BoundField HeaderText="Date"
DataField="date"
dataformatstring="{0:dd-MM-yyyy}" />
<asp:HyperLinkField HeaderText="Subject"
DataTextField="subject"
DataNavigateUrlFields="id"
DataNavigateUrlFormatString="http://intranet/Default2.aspx?id={0}" />
</Columns>
<pagersettings mode="Numeric"
position="Bottom"
pagebuttoncount="10"/>
<HeaderStyle HorizontalAlign="Left" />
</asp:gridview>
<asp:sqldatasource id="CustomersSource"
selectcommand="select id, subject, date from table order by id desc"
connectionstring="connection string here"
runat="server"/>
</div>
</form>
</body>
</html>
However, I want to use a querystring value in the sql statement. How do I do that?

you need something like this
<asp:SqlDataSource ID="ID" runat="server" ConnectionString="connectionString"
ProviderName="providerName"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products] WHERE ([CategoryID] = ?)">
<SelectParameters>
<asp:QueryStringParameter Type="Int32"
Name="CategoryID"
QueryStringField="CategoryID" />
</SelectParameters>
</asp:SqlDataSource>
Read full post at
https://web.archive.org/web/20211020150717/https://www.4guysfromrolla.com/articles/030106-1.aspx
Hope it helps.

Related

Master Pages and Child Pages Setup

I want to create a Master Page that has a toolbar (add,edit,delete,approve,unapprove) as well as a gridview as shown below. This Master Page will have a lot of children. I want to reused the gridview and the toolbar.. rather than adding both of them to each page i create.
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="JSPSite.master.vb" Inherits="SSPayroll.JSPSite" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="../Styles/Style1.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="Form1" runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/GSCV1.01 - Copy.png"
Height="73px" style="margin-top: 20px" Width="428px" />
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<LoggedInTemplate>
<asp:Label ID="Label2" runat="server" Text="User: " Font-Names="Cambria"></asp:Label><span class="bold">
<asp:LoginName ID="HeadLoginName" runat="server" Font-Names="Cambria" />
</span> [
<asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect"
LogoutPageUrl="~/" Font-Names="Cambria" Font-Size="Small" ForeColor="#D9D5D5" Font-Bold="True" LogoutText="Sign Out" />
]
<div>
</div>
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
<asp:Label ID="Label1" runat="server" Text="Date/Time" Font-Names="Cambria"
Font-Size="Small" ForeColor="#333333"></asp:Label>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="False"
IncludeStyleBlock="False" Orientation="Horizontal" BackColor="#FFFBD6"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#990000" StaticSubMenuIndent="10px" Enabled="True">
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<Items>
<asp:MenuItem Text="Menu1" Value="Tools">
<asp:MenuItem NavigateUrl="~/JSPayroll/Payment_Rules/PaymentRules.aspx" Text="Payment Rules" Value="Payment Rules"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#FFCC66" />
</asp:Menu>
</div>
</div>
<asp:ContentPlaceHolder ID="ToolBarPlaceHolder" runat="server" >
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Center">
<div>
<hr />
<asp:ImageButton ID="ImageButton1" runat="server" Height="48px" ImageUrl="~/IconsPack/Home.png" Width="48px" ToolTip="Home" CssClass="morph" PostBackUrl="~/JSPayroll/JSPDefault.aspx"/>
<asp:ImageButton ID="ImageButton2" runat="server" Height="48px" ImageUrl="~/IconsPack/Add.png" PostBackUrl="~/JSPayroll/Payment_Rules/PaymentRulesDetails.aspx" ToolTip="Add Record" CssClass="morph" Width="48px"/>
<asp:ImageButton ID="ImageButton3" runat="server" Height="48px" ImageUrl="~/IconsPack/Edit E.png" ToolTip="Edit Record" CssClass="morph" Width="48px" />
<asp:ImageButton ID="ImageButton4" runat="server" Height="48px" ImageUrl="~/IconsPack/ViewDetails.png" ToolTip="View Record Details" CssClass="morph" Width="48px" />
<asp:ImageButton ID="ImageButton5" runat="server" Height="48px" ImageUrl="~/IconsPack/Delete.png" ToolTip="Delete Record" CssClass="morph" Width="48px" />
<asp:ImageButton ID="ImageButton6" runat="server" Height="48px" ImageUrl="~/IconsPack/Approved.png" ToolTip="Approve Record" CssClass="morph" Width="48px"/>
<asp:ImageButton ID="ImageButton7" runat="server" Height="48px" ImageUrl="~/IconsPack/Denied.png" ToolTip="Unapprove Record" CssClass="morph" Width="48px"/>
<asp:ImageButton ID="ImageButton8" runat="server" Height="48px" ImageUrl="~/IconsPack/Update.png" ToolTip="Refresh Table" CssClass="morph" Width="48px"/>
<hr />
</div>
</asp:Panel>
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="GridViewPlaceHolder" runat="server">
<div class="EU_TableScroll" id="showData" style="display: block">
<asp:GridView ID="GridView1" runat="server" CssClass="EU_DataTable" AllowPaging="True"
PageSize="7" AutoGenerateColumns="False" EmptyDataText="No Data Available.">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="DataSource" runat="server">
</asp:ContentPlaceHolder>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
An Example of a Child Page using the master page from above.
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/JSPayroll/JSPSite.Master" CodeBehind="PaymentRules.aspx.vb" Inherits="SSPayroll.PaymentRules" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="DS" ContentPlaceHolderID ="DataSource" runat ="server">
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=sspEntities" DefaultContainerName="sspEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="GeneralRules">
</asp:EntityDataSource>
</asp:Content>
Basically what i want to do is.. In my child page just configure the Data source for each page, attached it to the gridview from the master page and the preform my task.. add, edit, delete (buttons in my master page). I am new to this and dont really have an idea of how to go about this. Some help would be appreciated. Also If someone can tell me what i am doing actually makes sense rather than adding gridviews and toolbar to each page i create. Please let me know. Thank you.
EDITED - With Answer.
Dim ContentPlaceHolder As ContentPlaceHolder
Dim gv As GridView
ContentPlaceHolder = CType(Master.FindControl("GridViewPlaceHolder"), ContentPlaceHolder)
If Not ContentPlaceHolder Is Nothing Then
gv = CType(ContentPlaceHolder.FindControl("GridView1"), GridView)
If Not gv Is Nothing Then
Dim es As EntityDataSource = EntityDataSource1
gv.DataSource = es
gv.DataBind()
End If
End If
Dim ContentPlaceHolder As ContentPlaceHolder
Dim gv As GridView
ContentPlaceHolder = CType(Master.FindControl("GridViewPlaceHolder"), ContentPlaceHolder)
If Not ContentPlaceHolder Is Nothing Then
gv = CType(ContentPlaceHolder.FindControl("GridView1"), GridView)
If Not gv Is Nothing Then
Dim es As EntityDataSource = EntityDataSource1
gv.DataSource = es
gv.DataBind()
End If
End If

zoom image in gridview

I am new to asp.net.I have gridview which displays data from database.One of the field contains image.The image which is shown dynamically as only image path is stored in database.
My table contains fields
Car_Name
Car_Id
Car_Photo
No_of_Seats
Now what i want is when user clicks on image i want a pop up image in modal.....or image should be zoomed something like that....
<%# Page Title="" Language="C#" MasterPageFile="~/Project/MasterPage/MasterPage.master"
AutoEventWireup="true" CodeFile="Reserve.aspx.cs" Inherits="Project_Reserve_Reserve" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link href="reserve.css" rel="stylesheet" type="text/css" />
<script src="../../javascript/jquery-1.9.0.js" type="text/javascript"></script>
<%-- <script src="myscript.js" type="text/javascript"></script>
<script src="f12.js" type="text/javascript"></script>--%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="homepageContentPlaceHolder" runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Select Start Date
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True"
TargetControlID="TextBox1">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<br />
Select End Date
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="TextBox2_CalendarExtender" runat="server" Enabled="True"
TargetControlID="TextBox2">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:AnimationExtender ID="RequiredFieldValidator2_AnimationExtender" runat="server"
Enabled="True" TargetControlID="RequiredFieldValidator2">
</asp:AnimationExtender>
<br />
<br />
<br />
Select Model <asp:DropDownList ID="ddlModel" runat="server"
AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Model_Name" DataValueField="Model_Id" OnSelectedIndexChanged="ddlModel_SelectedIndexChanged"
Width="100px">
<asp:ListItem Value="0">--Select--</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddlModel"
ErrorMessage="Select a Model"></asp:RequiredFieldValidator>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Model]"></asp:SqlDataSource>
<br />
<br />
<br />
<asp:GridView ID="gvcar" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" EmptyDataText="No data found!">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Car_Name" HeaderText="Car Name" />
<asp:BoundField DataField="No_of_Seats" HeaderText="Seats" />
<asp:TemplateField HeaderText="Photo">
<ItemTemplate>
<asp:Image Width="300" Height="200" ID="Image1" runat="server" ImageUrl='<%# Eval("Car_Photo") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<div>
<h3>
<em>Sorry...No Car is available rightnow for this model</em></h3>
</div>
</EmptyDataTemplate>
<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>
<asp:Button runat="server" ID="btnModalPopUp" Style="display: none" />
<br />
<br />
<br />
<asp:Button ID="btnbook" runat="server" Text="Book" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<br />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Following links might be helpful to you:
http://technico.qnownow.com/zoom-image-on-mouse-over-in-asp-net-gridview-control/
and
http://www.aspdotnet-suresh.com/2011/12/jquery-fancy-zoom-effect-for-image-in.html
hope its helpful.

ASP.NET Formview not correctly Updating

I'm converting my website from Classic ASP to ASP.net and outside of a few bumps, I've had no problems until today. But I am learning on the fly.
I'm trying to update a record in a formview and every time I do, I get the following error: "Must declare the scalar variable "#FirstName"".
I've googled and searched, and can't see what I'm doing wrong. I'm sure there's something little that I'm doing incorrect.
<asp:FormView ID="formRecruit" runat="server" DataSourceID="sourceRecruit"
EnableModelValidation="True" DataKeyNames="ID">
<ItemTemplate>
<asp:Table ID="Table1" Width="100%" runat="server">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell Width="50%">
<asp:Table ID="Table2" Width="100%" HorizontalAlign="Center" runat="server">
<asp:TableRow ID="TableRow2" runat="server">
<asp:TableCell>
<asp:Table ID="Table3" Width="100%" runat="server">
<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell>Name:</asp:TableCell>
<asp:TableCell><%#Eval("FirstName") %></asp:TableCell>
<asp:TableCell><asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="LinkButton1" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
<EditItemTemplate>
<asp:Table ID="Table1" Width="100%" runat="server">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell Width="50%">
<asp:Table ID="Table2" Width="100%" HorizontalAlign="Center" runat="server">
<asp:TableRow ID="TableRow2" runat="server">
<asp:TableCell>
<asp:Table ID="Table3" Width="100%" runat="server">
<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell>Name:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="txtFirstName" runat="server" Text='<%#Bind("FirstName") %>'/></asp:TableCell>
<asp:TableCell><asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="LinkButton1" /><asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="LinkButton2" CausesValidation="false" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sourceRecruit" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
SelectCommand="SELECT * FROM [Players] WHERE ([ID] = #ID)"
UpdateCommand="UPDATE [Players] SET [FirstName] = #FirstName WHERE [ID] = #ID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="ID" Name="ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Not 100% sure, but try to have the SqlDataSource this way and see if it works:
<asp:SqlDataSource ID="sourceRecruit" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
SelectCommand="SELECT * FROM [Players] WHERE ([ID] = #ID)"
UpdateCommand="UPDATE [Players] SET [FirstName] = #FirstName WHERE [ID] = #ID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="ID" Name="ID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="FirstName" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
You may also want to try converting the asp:Table, asp:TableRow tags etc to their HTML equivalent. It's been quite some time since I last worked with ASP.NET, but if I remember right, the controls somehow does not play well with data sources when you put them inside some other server controls.

Binding dropdownlist to dropdownlist to detailsview ASP.NET C#

I'm trying to bind a Dropdownlist to a Detailsview control in a page where the result of the second Dropdownlist depends on the first one. I could bind a single Dropdownlist to a Detailsview but if I add another Dropdownlist where the result depends on the first one the details view wont show anything unless you refresh the page.
So is there any way I could post the result of the detailsview automatically if the second dropdown is selected? I'm currently studying this but I couldnt get it.
Here's my sample code
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="LibrarySystem.Member.Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h3>
Search</h3>
<p>
Choose a category
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="categoryDataSource" DataTextField="name"
DataValueField="categoryid">
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT categoryid, name FROM dbo.TblCategory">
</asp:SqlDataSource>
</p>
<p>
Choose a title
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
DataSourceID="bookDataSource" DataTextField="booktitle" DataValueField="bookid">
</asp:DropDownList>
<asp:SqlDataSource ID="bookDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [booktitle], [bookid] FROM [TblBooks] WHERE ([categoryid] = #categoryid)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="categoryid"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<p>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="bookid" DataSourceID="bookdetailsDataSource"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="bookid" HeaderText="ID/ISBN" ReadOnly="True"
SortExpression="bookid" />
<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" />
<asp:BoundField DataField="lastname" HeaderText="Author"
SortExpression="lastname" />
<asp:BoundField DataField="firstname" HeaderText=""
SortExpression="firstname" />
<asp:BoundField DataField="description" HeaderText="Description"
SortExpression="description" />
<asp:BoundField DataField="name" HeaderText="Category" SortExpression="name" />
<asp:BoundField DataField="dateadded" HeaderText="Date added"
SortExpression="dateadded" />
<asp:BoundField DataField="quantity" HeaderText="No. of copies"
SortExpression="quantity" />
<asp:BoundField DataField="EmployeeID" HeaderText="Reserved by"
SortExpression="EmployeeID" />
<asp:BoundField DataField="reservedate" HeaderText="Reserved date"
SortExpression="reservedate" />
<asp:BoundField DataField="statusname" HeaderText="Status"
SortExpression="statusname" />
</Fields>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
Any help would be much appreciated ;)
Thanks in advance
You have to put your Dependent dropdown datasource in the parent template field. it will be look like...
<asp:TemplateField HeaderText="Category">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="categoryDataSource"
DataTextField="name" DataValueField="categoryid">
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT categoryid, name FROM dbo.TblCategory"></asp:SqlDataSource>
<asp:SqlDataSource ID="bookDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [booktitle], [bookid] FROM [TblBooks] WHERE ([categoryid] = #categoryid)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="categoryid" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="bookDataSource"
DataTextField="booktitle" DataValueField="bookid">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>

Passing Value from one Gridview to another page Gridview

Hello mates i have a page View All Applicants.aspx with gridview and a link button
i want to redirect to page View Applicant Detail.aspx when i click on link button and i want to show data in gridview on View Applicant Detail.aspx page based on the previous page values.
here is the code for View All Applicants.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="View All Applicants.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div><center>
</center>
<center style="background-color: silver">
</center>
<center>
<strong><span style="font-size: 16pt">List of All Applicants</span></strong></center>
<center style="background-color: silver">
</center>
<center>
</center>
<center>
</center>
<center>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True"
>
<Columns>
<asp:BoundField DataField="PersonName" HeaderText="PersonName" SortExpression="PersonName" />
<asp:BoundField DataField="DegreeName" HeaderText="DegreeName" SortExpression="DegreeName" />
<asp:BoundField DataField="InstituteName" HeaderText="InstituteName" SortExpression="InstituteName" />
<asp:BoundField DataField="ExperienceYears" HeaderText="ExperienceYears" SortExpression="ExperienceYears" />
<asp:BoundField DataField="OrganizationName" HeaderText="OrganizationName" SortExpression="OrganizationName" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:TemplateField HeaderText="Applicant Detail">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Cancel"
OnClick="LinkButton1_Click" Text="View"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString8 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString8.ProviderName %>" SelectCommand="SELECT Distinct PERSONALDETAIL.PersonName, DEGREE.DegreeName, INSTITUTE.InstituteName, EXPERIENCE.ExperienceYears, EXPERIENCE.OrganizationName, EXPERIENCE.Designation FROM EXPERIENCE, EXPERIENCE EXPERIENCE_1, PERSONALDETAIL, DEGREE, INSTITUTE WHERE EXPERIENCE.ExperienceID = EXPERIENCE_1.ExperienceID">
</asp:SqlDataSource>
</center>
<center>
</center>
<center>
</center>
<center style="background-color: silver">
</center>
</div>
</form>
</body>
</html>
and for View Applicant Detail.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="View Applicant Detail.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div><center>
</center>
<center style="background-color: silver">
</center>
<center>
<strong><span style="font-size: 16pt">Job Applicant Detail</span></strong></center>
<center style="background-color: silver">
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ResumeID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ResumeID" HeaderText="ResumeID" InsertVisible="False"
ReadOnly="True" SortExpression="ResumeID" />
<asp:BoundField DataField="TotalExperienceYears" HeaderText="TotalExperienceYears"
SortExpression="TotalExperienceYears" />
<asp:BoundField DataField="TotalExperienceMonths" HeaderText="TotalExperienceMonths"
SortExpression="TotalExperienceMonths" />
<asp:BoundField DataField="ExperienceSummary" HeaderText="ExperienceSummary" SortExpression="ExperienceSummary" />
<asp:BoundField DataField="DetailedCVName" HeaderText="DetailedCVName" SortExpression="DetailedCVName" />
<asp:BoundField DataField="AdditionalQualification" HeaderText="AdditionalQualification"
SortExpression="AdditionalQualification" />
<asp:BoundField DataField="ExtraCurricular" HeaderText="ExtraCurricular" SortExpression="ExtraCurricular" />
<asp:BoundField DataField="Skills" HeaderText="Skills" SortExpression="Skills" />
<asp:BoundField DataField="TentativeFromDate" HeaderText="TentativeFromDate" SortExpression="TentativeFromDate" />
<asp:BoundField DataField="PageIndex" HeaderText="PageIndex" SortExpression="PageIndex" />
<asp:BoundField DataField="PersonalDetailID" HeaderText="PersonalDetailID" SortExpression="PersonalDetailID" />
<asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID" SortExpression="DepartmentID" />
<asp:BoundField DataField="DesignationID" HeaderText="DesignationID" SortExpression="DesignationID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString5 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString5.ProviderName %>" SelectCommand="SELECT * FROM [RESUME]">
</asp:SqlDataSource>
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center style="background-color: silver">
</center>
</div>
</form>
</body>
</html>
You don't have to do a postbask to redirect the user to the details page, you can edit your template column to go directly to the URL of the details page along with a GET variable of the ID needed for the lookup.
<asp:TemplateField HeaderText="Applicant Detail">
<ItemTemplate>
<asp:HyperLink NavigateUrl="DetailsView.aspx?ResumeID=" + "<%# Bind("ResumeID") %>" Text="Visit W3Schools!" Target="_blank" runat="server" />
</ItemTemplate>
</asp:TemplateField>
In your Details page, do Request.QueryString("ResumeID") to get ID needed to do the lookup.

Categories

Resources