我正在学习ASP.NET(C#)并遇到了这段代码:
<asp:DropDownList
id="ddlMovieCategory"
DataSourceID="srcMovieCategories"
DataTextField="Name"
DataValueField="Id"
Runat="server" />
<asp:Button
id="btnSelect"
Text="Select"
Runat="server" />
<asp:GridView
id="grdMovies"
DataSourceID="srcMovies"
CssClass="gridView"
Runat="server" />
<asp:SqlDataSource
id="srcMovieCategories"
SelectCommand="SELECT Id, Name FROM MovieCategories"
ConnectionString="<%$ ConnectionStrings:Movies %>"
Runat="server" />
<asp:SqlDataSource
id="srcMovies"
SelectCommand="SELECT Title,Director FROM Movies
WHERE CategoryId=@Id"
ConnectionString="<%$ ConnectionStrings:Movies %>"
Runat="server">
<SelectParameters>
<asp:ControlParameter
Name="Id"
ControlID="ddlMovieCategory"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
我想知道最后一个控件的SelectCommand中的@符号是如何工作的。它按预期工作,但我不明白它是如何得到@ ie之后的值,即如果它是使用在ASP标签中转义的变量那么它是如何知道Id引用DropDownList的?选定的项目。
编辑:我想我可能找到了解决方案。我认为这是来自这段代码,我是否正确:
<asp:ControlParameter
Name="Id"
ControlID="ddlMovieCategory"
PropertyName="SelectedValue" />
</SelectParameters>
答案 0 :(得分:1)
以下字符串
<?php
echo $ip = $_SERVER['REMOTE_ADDR'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "http://ipinfo.io/{$ip}/json"
));
$details = json_decode(curl_exec($curl));
curl_close($curl);
echo "<br>".$details->ip;
echo "<br>".$details->country;
echo "<br>".$details->region;
echo "<br>".$details->city;
echo "<br>".$details->loc;
echo "<br>".$details->postal;
echo "<br>".$details->org;
表示参数化的sql查询。在将此查询发送到数据库之前,参数Id "SELECT Title,Director FROM Movies WHERE CategoryId=@Id"
的值将分配给@Id
,以便执行。
我们首先使用参数化查询,以避免SQL injections。