<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Gridview_Eval_Bind.WebForm1" %>
<!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">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border: 1px solid #ccc;
width: 450px;
margin-bottom: -1px;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataSourceID="SqlDataSource1" DataKeyNames="CustomerId">
<Columns>
<asp:TemplateField HeaderText="ContactName" ItemStyle-Width="150">
<ItemTemplate>
<asp:TextBox ID="txtContactName" runat="server"
Text='<%# Bind("ContactName") %>'/>
Text='<%# Bind("ContactName") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" ItemStyle-Width="150">
<ItemTemplate>
<asp:TextBox ID="txtCountry" runat="server"
Text='<%# Bind("Country") %>'/>
Text='<%# Bind("Country") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ContactName" ItemStyle-Width="250">
<ItemTemplate>
<asp:LinkButton ID="LinkButtonContactName" runat="server" Width="250"
Text='<%# Bind("ContactName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" ItemStyle-Width="250">
<ItemTemplate>
<asp:LinkButton ID="LinkButtonCountry" runat="server" Width="250"
Text='<%# Bind("Country") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="100">
<ItemTemplate>
<asp:LinkButton Text="Update" runat="server" CommandName="Update" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT
CustomerId, ContactName, Country FROM Customers"
UpdateCommand="UPDATE Customers
SET ContactName = @ContactName,
Country = @Country WHERE
CustomerId = @CustomerId">
<UpdateParameters>
<asp:Parameter Name="CustomerId" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Country" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
No comments:
Post a Comment