Asp.Net数据网格视图:Where子句不起作用
本文关键字:Where 子句 不起作用 视图 网格 Net 数据 数据网 Asp | 更新日期: 2023-09-27 18:19:34
这是我的DataGridView
设计代码:
SelectCommand="SELECT [CNAME] FROM [Registration] WHERE ([USERNAME] = @USERNAME)">
<SelectParameters>
<asp:SessionParameter Name="USERNAME" SessionField="username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
我的代码背后:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["username"] = "1";
}
}
程序正在运行,但登录后没有输出。
您可以使用QueryString
而不是Session
SelectCommand="SELECT [CNAME] FROM [Registration] WHERE ([USERNAME] = @USERNAME)">
<SelectParameters>
<asp:querystringparameter name="USERNAME" type="String" querystringfield="username" />
</SelectParameters>
</asp:SqlDataSource>
这是代码(但我想我的表值搞错了)
namespace IncendoVentures
if (Session["New"] != null)
{
Label_welcome.Text += Session["New"].ToString();
}
else
Response.Redirect("MainPage.aspx");
if (!IsPostBack)
{
Session["username"] = 1;
}
}
protected void GridView1_RowCommand(object sender, EventArgs e)
{
Response.Redirect("Uploads.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("ChangePassword.aspx");
}
protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
{
Response.Redirect("MainPage.aspx");
}
}
}
设计代码:
<asp:Label ID="Label1" runat="server"
style="color: #000000; font-weight: 700; text-decoration: underline; font-size: x-large"
Text="SELECT COMPANY"></asp:Label>
<br />
<br />
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [CNAME] FROM [Registration] WHERE ([USERNAME] = @USERNAME)">
<SelectParameters>
<asp:SessionParameter Name="USERNAME" SessionField="username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2" DataSourceID="SqlDataSource1" ForeColor="Black"
style="font-size: large; margin-right: 0px;" Width="647px" AllowPaging="True"
onrowcommand="GridView1_RowCommand">
<RowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="CNAME" HeaderText="CNAME"
SortExpression="CNAME" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<br />
<br />
</div>
</form>