这个代码效果很好,除了获取帖子值...我现在选择硬编码,但我想从表格帖子中获取值并从中填充...我希望有一种方式使用内联asp.net(vb.net)执行此操作...
<%@ Page language="VB" %>
<!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 id="Head1" runat="server">
<title>ListView Templates Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Modifying Quantities for: </h3>
<asp:SqlDataSource ID="Sql" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT [name],[id] FROM [markets]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="yearSQLDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT distinct(year) as year from transactions order by year asc">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT shortname, id from products order by name asc">
</asp:SqlDataSource>
<asp:Label ID="market" runat="server" Text="Market:" />
<asp:DropDownList ID="markets" runat="server"
DataSourceID="Sql" DataTextField="name" DataValueField="id" >
</asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="Products:" />
<asp:DropDownList ID="products" runat="server"
DataSourceID="SqlDataSource1" DataTextField="shortname" DataValueField="id" >
</asp:DropDownList>
<!--TODO use databind in Page_Load to fill from SQL and then use distributor ID instead of name to match-->
<asp:Label ID="year" runat="server" Text="Year:" />
<asp:DropDownList ID="years" runat="server"
DataSourceID="yearSQLDataSource" DataTextField="year" DataValueField="year" >
</asp:DropDownList>
<asp:button ID="Button1" runat="server" text="Submit" postbackurl="fourrosesformDataList3.aspx" />
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="id"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">Action</th>
<th id="Th2" runat="server">Month</th>
<th id="Th3" runat="server">Quantity</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="Label1" runat="Server" Text='<%#Eval("MonthName") %>' />
</td>
<td>
<asp:Label DataTextField = "standardcase" ID="standardcase" runat="Server" Text='<%#Eval("standardcase") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr style="background-color: #ADD8E6">
<td>
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="Label3" runat="Server" Text='<%#Eval("MonthName") %>' />
</td>
<td>
<asp:TextBox ID="standardcase" DataTextField = "standardcase" runat="server" Text='<%# Bind("standardcase") %>'
MaxLength="50" /><br />
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT standardcase, shortname, datename(month,dateadd(month, t.month - 1, 0)) as MonthName, t.id as id
from transactions t, products p where p.id=t.product_id and year = 2009 and market_id = 1 and product_id = 1"
UpdateCommand="UPDATE transactions
SET standardcase = @standardcase
WHERE id = @id"
>
</asp:SqlDataSource>
</form>
</body>
</html>
所以代替&#34;其中p.id = t.product_id和year = 2009和market_id = 1且product_id = 1&#34;
我想做&#34;其中p.id = t.product_id和year = @postYear和market_id = @postMarket和product_id = @ postProduct&#34;从页面顶部的表格。
答案 0 :(得分:1)
使用asp:sqldatasource的selectparameters标记。具体如何操作取决于您是否从当前页面上的控件获取值。
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
selectcommand="SELECT standardcase, shortname, datename(month,dateadd(month, t.month - 1, 0)) as MonthName, t.id as id
from transactions t, products p where p.id=t.product_id and year = @year and market_id = @market and product_id = @product">
<selectparameters>
<asp:controlparameter name="year" controlid="DropDownList1" propertyname="SelectedValue"/>
<asp:controlparameter name="market" controlid="DropDownList1" propertyname="SelectedValue"/>
<asp:controlparameter name="products" controlid="DropDownList1" propertyname="SelectedValue"/>
</selectparameters>
</asp:sqldatasource>
请注意,这确实会留下漏洞,有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.selectparameters(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2。
答案 1 :(得分:0)
formparamter属性对我有用:
我也可以看一下控制参数...... T