刚才在鼓捣GridView与FormView,记得前一段时间在做时,点击gridview中的一项会在formview中显示详细的数据,而在 formview中只有编写了ItemTemplate等模板才会显示,我清楚的记得上次我并没有手工去编写itemTemplate模板,在查看、编辑、删除时的模板都是自动生成的,这次始终不成功,我又不愿意去手工写一些itemtemplate,如果有20个字段,我都手写就太累了。。。
偷懒之余,就用FormView的向导功能来做,不料,那些模板又自动生成了。怪。
也自动生成了如下模板:
<EditItemTemplate>
CustomerID:
<asp:Label ID="CustomerIDLabel1" runat="server" Text='<%# Eval("CustomerID") %>'>
</asp:Label><br />
CompanyName:
<asp:TextBox ID="CompanyNameTextBox" runat="server" Text='<%# Bind("CompanyName") %>'>
</asp:TextBox><br />
ContactName:
<asp:TextBox ID="ContactNameTextBox" runat="server" Text='<%# Bind("ContactName") %>'>
</asp:TextBox><br />
ContactTitle:
<asp:TextBox ID="ContactTitleTextBox" runat="server" Text='<%# Bind("ContactTitle") %>'>
</asp:TextBox><br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox><br />
City:
<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>'>
</asp:TextBox><br />
Region:
<asp:TextBox ID="RegionTextBox" runat="server" Text='<%# Bind("Region") %>'>
</asp:TextBox><br />
PostalCode:
<asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<%# Bind("PostalCode") %>'>
</asp:TextBox><br />
Country:
<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>'>
</asp:TextBox><br />
Phone:
<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>'>
</asp:TextBox><br />
Fax:
<asp:TextBox ID="FaxTextBox" runat="server" Text='<%# Bind("Fax") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="更新">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消">
</asp:LinkButton>
</EditItemTemplate>
CustomerID:
<asp:Label ID="CustomerIDLabel1" runat="server" Text='<%# Eval("CustomerID") %>'>
</asp:Label><br />
CompanyName:
<asp:TextBox ID="CompanyNameTextBox" runat="server" Text='<%# Bind("CompanyName") %>'>
</asp:TextBox><br />
ContactName:
<asp:TextBox ID="ContactNameTextBox" runat="server" Text='<%# Bind("ContactName") %>'>
</asp:TextBox><br />
ContactTitle:
<asp:TextBox ID="ContactTitleTextBox" runat="server" Text='<%# Bind("ContactTitle") %>'>
</asp:TextBox><br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox><br />
City:
<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>'>
</asp:TextBox><br />
Region:
<asp:TextBox ID="RegionTextBox" runat="server" Text='<%# Bind("Region") %>'>
</asp:TextBox><br />
PostalCode:
<asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<%# Bind("PostalCode") %>'>
</asp:TextBox><br />
Country:
<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>'>
</asp:TextBox><br />
Phone:
<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>'>
</asp:TextBox><br />
Fax:
<asp:TextBox ID="FaxTextBox" runat="server" Text='<%# Bind("Fax") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="更新">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消">
</asp:LinkButton>
</EditItemTemplate>
下面是该FormView的DataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
InsertCommand="insert into customers (CustomerID,CompanyName,ContactName,ContactTitle,Address,City) values (@customerid,@companyname,@contactName,@contactTitle,@address,@city)"
SelectCommand="select * from customers where customerid=@customerid" UpdateCommand="update customers set companyname=@companyname,contactName=@contactName,contactTitle=@contactTitle where customerid=@customerid">
<UpdateParameters>
<asp:Parameter Name="companyname" />
<asp:Parameter Name="contactName" />
<asp:Parameter Name="contactTitle" />
<asp:Parameter Name="customerid" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Direction="input" Name="customerid" Type="string" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="customerid" />
<asp:Parameter Name="companyname" />
<asp:Parameter Name="contactName" />
<asp:Parameter Name="contactTitle" />
<asp:Parameter Name="address" />
<asp:Parameter Name="city" />
</InsertParameters>
</asp:SqlDataSource>
InsertCommand="insert into customers (CustomerID,CompanyName,ContactName,ContactTitle,Address,City) values (@customerid,@companyname,@contactName,@contactTitle,@address,@city)"
SelectCommand="select * from customers where customerid=@customerid" UpdateCommand="update customers set companyname=@companyname,contactName=@contactName,contactTitle=@contactTitle where customerid=@customerid">
<UpdateParameters>
<asp:Parameter Name="companyname" />
<asp:Parameter Name="contactName" />
<asp:Parameter Name="contactTitle" />
<asp:Parameter Name="customerid" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Direction="input" Name="customerid" Type="string" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="customerid" />
<asp:Parameter Name="companyname" />
<asp:Parameter Name="contactName" />
<asp:Parameter Name="contactTitle" />
<asp:Parameter Name="address" />
<asp:Parameter Name="city" />
</InsertParameters>
</asp:SqlDataSource>
直到现在还是晕晕的,不知道怎么样才能使之自动生成模板,难道只有在向导的情况下才会生成?