Click here to Skip to main content
15,903,800 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in ObjectDataSource and SqlDataSource ,Commands Parameters where received their values ​?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.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>: DataSet in Web :</title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:Button runat="server" ID="Submit" Text="Do Post Back" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShopConnectionString2 %>"
            DeleteCommand="DELETE FROM [Customer] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Customer] ([Code], [FirstName], [LastName], [TimeStamp]) VALUES (@Code, @FirstName, @LastName, @TimeStamp)"
            SelectCommand="SELECT * FROM [Customer]" UpdateCommand="UPDATE [Customer] SET [Code] = @Code, [FirstName] = @FirstName, [LastName] = @LastName  WHERE [ID] = @ID">
        
        
        
        
            Product<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
                DataSourceID="SqlDataSource1" Font-Bold="False" Font-Size="11pt">
                <columns>
                    <asp:CommandField ShowEditButton="True" />
                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                        SortExpression="ID" />
                    <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
                </columns>
            
        
    </div>
    </form>
</body>
</html>
Posted
Updated 29-Apr-11 4:47am
v3

1 solution

If you look at the GridView declaration you'll see this attribute:

DataSourceID="SqlDataSource1"


This connects the GridView and the DataSource. The DataSource then implicitly maps the DataField attribute to the parameters:

<asp:BoundField DataField="Code"
 
Share this answer
 
Comments
[no name] 29-Apr-11 10:41am    
I Purpose is the Commands parameters .such as @ID,@LastName
jim lahey 29-Apr-11 10:52am    
Pardon? I don't understand what you said.

Look at the DataField attributes and the parameter names. they're the same, ergo implicitly mapped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900