add click on ASP.net - c#

I am working on a college project and have a gridview that I have to add more rows to.
I have two text fields and a button.
Everything seems to be fine except the button part of the code in the .cs file
What am I doing wring?
Its to make a list of Wines with an ID and a Title and a Year:
Wine.aspx:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Wine.aspx.cs" Inherits="WineNotProject2.AdminPages.Wine" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<br /><br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
</Columns>
</asp:GridView>
<p><asp:Label ID="lblTitle" runat="server" Text="Wine Title"></asp:Label><br />
<asp:TextBox ID="txtTitle" runat="server" Width="176px"></asp:TextBox><br />
<p><asp:Label ID="lblYear" runat="server" Text="Wine Year"></asp:Label><br />
<asp:TextBox ID="txtYear" runat="server" Width="176px"></asp:TextBox><br />
</p>
<asp:Button ID="btnAdd" runat="server" Text="Add Wine" OnClick="btnAdd_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [id], [Title], [Year] FROM [Wine]">
</asp:SqlDataSource>
</asp:Content>
Wine.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WineNotProject2.AdminPages
{
public partial class Wine : System.Web.UI.Page
{
private WineEntities10 ent2 = new WineEntities10();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RefreshGrid();
}
}
private void RefreshGrid()
{
GridView2.DataSource = ent2.Wines.ToList();
GridView2.DataBind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Wine w2 = new Wine();
w2.Title = txtTitle.Text;
w2.Year = txtYear.Text;
ent2.Wines.AddObject(w2);
ent2.SaveChanges();
}
}
}
UPDATE:
The error message is:
Error 3 'WineNotProject2.AdminPages.Wine' does not contain a definition for 'Year' and no extension method 'Year' accepting a first argument of type 'WineNotProject2.AdminPages.Wine' could be found (are you missing a using directive or an assembly reference?) C:\Visual Studio 2010\Projects\WineNotProject7\WineNotProject2\AdminPages\Wine.aspx.cs 30 20 WineNotProject2

I think you need to call RefreshGrid after you have added the new Wine:
protected void btnAdd_Click(object sender, EventArgs e)
{
Wine w2 = new Wine();
w2.Title = txtTitle.Text;
w2.Year = txtYear.Text;
ent2.Wines.AddObject(w2);
ent2.SaveChanges();
RefreshGrid(); // <-------
}
Maybe you also need to parse the year to int:
w2.Year = int.Parse(txtYear.Text);

The problem is you have two classes with same name Wine.
public partial class **Wine** : System.Web.UI.Page
**Wine** w2 = new **Wine**();
Rename ASP.Net page's name to WineList so that
its class name should become public partial class **WineList**

Your code was looking good ,But you miss call the RefreshGrid() end of add button
for
protected void btnAdd_Click(object sender, EventArgs e)
{
Wine w2 = new Wine();
w2.Title = txtTitle.Text;
w2.Year = txtYear.Text;
ent2.Wines.AddObject(w2);
ent2.SaveChanges();
**RefreshGrid**
}
If ent2.SaveChanges(); is not working ,then use ent2.SubmitChanges();

Related

Cannot search on gridview C# aspnet

I'm implementing a search bar to filter GridView1. I followed this tutorial but when it doesnt work. I want to filter the UserID and show only the specific output match the user input. I clicked on search but nothing work, it just refreshed the page and nothing else.
aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Manager.Master" AutoEventWireup="true" CodeBehind="ExceptionReport.aspx.cs" Inherits="Bracelet.ExceptionReport" %>
<%# Register Assembly="Microsoft.ReportViewer.WebForms" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="col-md-10">
<div class="content-box-large">
<div class="panel-heading">
<div class="panel-title">Admin Log Report</div>
</div>
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button Text="Search" runat="server"/>
<div class="panel-body">
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="UserID">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True" SortExpression="UserID" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="UserEmail" HeaderText="UserEmail" SortExpression="UserEmail" />
<asp:BoundField DataField="logtime" HeaderText="logtime" SortExpression="logtime" />
</Columns>
</asp:GridView>
</div>
</div>
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="Bracelet.BraceletDataContext" EntityTypeName="" TableName="Users">
</asp:LinqDataSource>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Bracelet.BraceletDataContext" EntityTypeName="" TableName="Users" Where="UserRole == #UserRole">
<WhereParameters>
<asp:Parameter DefaultValue="Admin" Name="UserRole" Type="String" />
</WhereParameters>
</asp:LinqDataSource>
</div>
</asp:Content>
Full code .cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
namespace Bracelet
{
public partial class ExceptionReport : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
protected void Search(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["BraceletConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT UserID, UserName, UserEmail, logtime FROM [User] WHERE UserID LIKE '%' + #UserID + '%'";
cmd.Connection = con;
cmd.Parameters.AddWithValue("#UserID ", txtSearch.Text.Trim());
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGrid();
}
}
}
Not too bad.
but, there are few errors and issues.
first up, you have search button - but it has no "id" assigned.
You probably should get in the habit of simple drag + drop the button in from the tool box.
So, we now have this for the button and the grid:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button ID="cmdSearch" runat="server" Text="Search" />
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="UserID">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True" SortExpression="UserID" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="UserEmail" HeaderText="UserEmail" SortExpression="UserEmail" />
<asp:BoundField DataField="logtime" HeaderText="logtime" SortExpression="logtime" />
</Columns>
</asp:GridView>
NOTE carefull in above, how we gave the button a "ID"
So, our basic code to load up the grid?
FYI: huge love, hugs, high-5's for checking is-post back!!!
(always, always do that!!!).
So, our code to load things up can thus look like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
this.BindGrid();
}
void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["BraceletConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT UserID, UserName, UserEmail, logtime FROM [User]", con))
{
// optional text box filter (blank = all)
if (txtSearch.Text != "")
{
cmd.CommandText += " WHERE UserID LIKE '%' + #UserID + '%'";
cmd.Parameters.Add("#UserID", SqlDbType.Text).Value = txtSearch.Text;
}
con.Open();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
Note how we did not need that data adaptor - not needed.
However, we still not created the code stub for the button click (that's why your code is not working - you did not give your button a "id"
So, in the designer - double click on the button. That will create the "event" for you, and jump to the code editor, and we have this:
protected void cmdSearch_Click(object sender, EventArgs e)
{
this.BindGrid();
}
so, in general - don't type in the "event" stubs for a button - double click on the button - it will create + wire it up for you.
Note close, if I flip back to mark-up, the button has become this:
<asp:Button ID="cmdSearch" runat="server" Text="Search" OnClick="cmdSearch_Click" />

How to download pdf file using asp.net?

I upload file and stored in Data folder in server
File path:
Project Name
|_bin
|_css
|_Data
|_Mohamedfaisal.pdf
this is my asp.net code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
namespace Expatriates {
public partial class FileUploadForm: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
if (FileUpload1.HasFile) {
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Data/") + FileUpload1.FileName);
}
DataTable dt = new DataTable();
dt.Columns.Add("File", typeof(string));
dt.Columns.Add("size", typeof(string));
dt.Columns.Add("type", typeof(string));
foreach(string strFile in Directory.GetFiles(Server.MapPath("~/Data/"))) {
FileInfo fi = new FileInfo(strFile);
dt.Rows.Add(fi.Name, fi.Length, fi.Extension);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
if (e.CommandName == "Download") {
Response.Clear();
Response.Write(e.CommandArgument);
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Data/") + e.CommandArgument); // error occured
Response.End();
}
}
}
}
Front End asp.net
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="FileUploadForm.aspx.cs" Inherits="Expatriates.FileUploadForm" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family:Arial;">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="File">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Download" Text='<%# Eval("File") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Size" HeaderText="Size in Bytes" />
<asp:BoundField DataField="Type" HeaderText="File Type" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
my front end design
UI design
when I click that link it shows that following error message
An exception of type 'System.IO.DirectoryNotFoundException' occurred
in mscorlib.dll but was not handled in user code
Additional information: Could not find a part of the path 'F:\Visual
Studio Project\Expatriates\Expatriates\Data\'.
Uploading file is working perfectly, But I am not getting a download.
You don't supply a commandArgument for your RowCommand event. Change
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Download" Text='<%# Eval("File") %>'></asp:LinkButton>
to
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Download" CommandArgument='<%# Eval("File") %>' Text='<%# Eval("File") %>'></asp:LinkButton>
The only reason your code could fail would be if e.CommandArgument doesn't have a valid file name. I think the Command Argument isn't being passed for some reason, please look into your markup.
You have to explicitly specify CommandArgument for a LinkButton like this:
CommandArgument='<%# Eval("File") %>'

Why does my ASP.NET App show an extra table?

This is a hybrid (MVC and Web forms) Web app to rate doctors. Here is my code for the ratings Web form. Why is there an extra table with the first record under the GridView? It happened after I pressed "Select" in the first row, but why does it stay there after I stop and run it again? It's not a cache problem, because it shows in different browsers. Thanks in advance!
<%# Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Rating.aspx.cs" Inherits="MidtermApplication.Rating" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ObjectDataSource ID="ObjectDataSourceDoctor" runat="server" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="GetDoctor" TypeName="MidtermApplication.Models.TestApplicationDoctorRepo" UpdateMethod="Update" DataObjectTypeName="MidtermApplication.Models.Doctor">
</asp:ObjectDataSource>
<asp:GridView ID="GridViewDoctor" runat="server" DataSourceID="ObjectDataSourceDoctor" AutoGenerateColumns="False" OnSelectedIndexChanged="GridViewDoctor_SelectedIndexChanged">
<Columns>
<asp:ImageField DataImageUrlField="DoctorPicture" HeaderText="DoctorPicture">
</asp:ImageField>
<asp:BoundField DataField="DoctorName" HeaderText="DoctorName" SortExpression="DoctorName" />
<asp:BoundField DataField="DoctorSpecialty" HeaderText="DoctorSpecialty" SortExpression="DoctorSpecialty" />
<asp:TemplateField HeaderText="Rate Now">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="RateNow" Text="1"></asp:RadioButton>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="RateNow" Text="2"></asp:RadioButton>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="RateNow" Text="3"></asp:RadioButton>
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="RateNow" Text="4"></asp:RadioButton>
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="RateNow" Text="5"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField AccessibleHeaderText="Save Rating" HeaderText="Save Rating" Text="Save" />
<asp:CheckBoxField DataField="fave" HeaderText="Favorite" SortExpression="fave" InsertVisible="False" Visible="True" />
</Columns>
</asp:GridView>
</asp:Content>
Code behind:
namespace MidtermApplication
{
public partial class Rating : System.Web.UI.Page
{
TestApplicationDoctorRepo repo;
protected void Page_Load(object sender, EventArgs e)
{
TestApplicationDoctorRepo.InitApp(this);
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridViewDoctor_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Why is there an extra table with the first record under the GridView?
it is a details view, you can remove it in design mode in visual studio.
Update:
Solution:
You must create a new page, and design this page again.

Returning data from SQL in GridView for selected date on a calendar on click

I'm creating a rota system for a small-medium sized business as my final year project at uni. I'm trying to create a function where a user can click on the calendar and the system will automatically return the shifts for the selected date.
Here is the code:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Select date to show rota for selected date:
</h2>
<p>
<asp:Calendar ID="Calendar" runat="server" nextprevformat="shortmonth" OnSelectionChanged="Calendar_SelectionChanged" />
<br />
Date Selected: <asp:TextBox id="textSelected" runat="server" Text="2013-02-21" AutoPostBack="true"></asp:TextBox>
</p>
<asp:Label id="lbl" runat="server"></asp:Label>
<p> </p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Shift_ID" DataSourceID="SqlDataSource1" onselectedindexchanged="GridView1_SelectedIndexChanged" AllowSorting="True">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Shift_ID" HeaderText="Shift_ID" ReadOnly="True" SortExpression="Shift_ID" />
<asp:BoundField DataField="Shift_Date" HeaderText="Shift_Date" SortExpression="Shift_Date" />
<asp:BoundField DataField="Start_Time" HeaderText="Start_Time" SortExpression="Start_Time" />
<asp:BoundField DataField="End_Time" HeaderText="End_Time" SortExpression="End_Time" />
<asp:BoundField DataField="Employee_ID" HeaderText="Employee_ID" SortExpression="Employee_ID" />
<asp:BoundField DataField="Shift_Duration" HeaderText="Shift_Duration" SortExpression="Shift_Duration" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:rotasystemConnectionString %>" SelectCommand="SELECT [Shift_ID], [Shift_Date], [Start_Time], [End_Time], [Employee_ID], [Shift_Duration] FROM [Shift]">
</asp:SqlDataSource>
<p> </p>
</asp:Content>
And
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class CalendarSelect : System.Web.UI.Page
{
public string vconnstr;
public string strsql;
protected void Calendar_SelectionChanged(object o, EventArgs e)
{
textSelected.Text = Calendar.SelectedDate.ToString("yyyy-MM-dd");
if (Page.IsPostBack == true)
{
lbl.Text = "This needs to return a gridview showing the shifts for the date of:";
lbl.Text += "<br /> " + Calendar.SelectedDate.ToShortDateString();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { }
}
Check this one http://msdn.microsoft.com/en-us/library/ms228044%28v=vs.100%29.aspx
I have used it in my project.
It'll surely helps you.
Even i wanted to do it so i did it like this :
1- drag and drop calendar control and grid view
2- add a datasource to gridview and specify the columns like
select column1,2,3 from tablename where your_date_column = Control of the calendar . the configure datasource will give you option select the control
3- and its done :)
mine is working

C# Less obscure way to populate a DetailsView?

I can't seem to bind a single GridView's row to a DetailsView properly. Currently I have this:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.WebControls;
namespace WebApp
{
public partial class CrudGrid : System.Web.UI.UserControl
{
public const string EditCommand = "EditDialog";
public object DataSource
{
get { return Grid.DataSource; }
set { Grid.DataSource = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Grid_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
switch(e.CommandName)
{
case EditCommand:
{
int index;
if(!int.TryParse(e.CommandArgument.ToString(), out index))
throw new ArgumentException();
TableCellCollection cells = Grid.Rows[index].Cells;
Details.DataSource = new object[] { new DataSourceProvider(cells[2].Text, cells[3].Text, cells[4].Text) };
Details.DataBind();
DetailsPanel.Update();
break;
}
}
}
protected void Grid_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
private class DataSourceProvider
{
public string Cell1 { get; set; }
public string Cell2 { get; set; }
public string Cell3 { get; set; }
public DataSourceProvider(string cell1, string cell2, string cell3)
{
Cell1 = cell1;
Cell2 = cell2;
Cell3 = cell3;
}
}
}
}
and client-side:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="CrudGrid.ascx.cs" Inherits="Firelight.WebApp.WebControls.CrudGrid" %>
<asp:UpdatePanel ID="GridPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:ImageButton ID="GridInsert" ImageUrl="/images/crud/insert.png" runat="server" />
<asp:GridView ID="Grid" GridLines="None" AllowPaging="true" PageSize="15" runat="server"
OnRowCommand="Grid_OnRowCommand"
OnRowDeleting="Grid_OnRowDeleting"
>
<Columns>
<asp:ButtonField CommandName="EditDialog" ButtonType="Image" ImageUrl="/images/crud/edit.png" HeaderImageUrl="/images/crud/edit.png" />
<asp:ButtonField CommandName="Delete" ButtonType="Image" ImageUrl="/images/crud/delete.png" HeaderImageUrl="/images/crud/delete.png" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="DetailsPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:DetailsView ID="Details" GridLines="None" runat="server"
AutoGenerateRows="true" DefaultMode="ReadOnly" AllowPaging="false">
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
this "works": I get a list in the detailsview enumerating the cells I manually built into a class...
what I'd actually want is something similar to
Details.DataSource = Grid.Rows[index]
enumerating the fields and their names, but that doesn't seem to work properly either.
any suggestions or ideas?
this is for a usercontrol, in case it changes anything.
why dont you simply use master/details way to do this using griview item as a control parameter to the detailsview?
<asp:DetailsView AutoGenerateRows="False" DataKeyNames="au_id" DataSourceID="SqlDataSource3"
HeaderText="Author Details" ID="DetailsView1" runat="server" Width="275px">
<Fields>
<asp:BoundField DataField="au_id" HeaderText="au_id" ReadOnly="True" SortExpression="au_id" />
<asp:BoundField DataField="au_lname" HeaderText="au_lname" SortExpression="au_lname" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:Pubs %>" ID="SqlDataSource3"
runat="server" SelectCommand="SELECT [au_id], [au_lname] FROM [authors] WHERE ([au_id] = #au_id)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="au_id" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Something like this:
http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/GridViewMasterDetails.src

Categories

Resources