使用 asp:gridview 时遇到困难
我似乎在使用 asp:querystringparameter
和 asp:gridview
时遇到困难。到目前为止,我有以下内容,它只返回“无可用数据”:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
String strGroup = Request.QueryString["group"];
switch(strGroup){
case "Clients":
ClientSource.SelectCommand = @"select client_code,
client_name from table1 where client_name = @phrase";
break;
case "Addresses":
/*different query here*/
break;
case "Matters":
/*different query here*/
break;
default:
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family:Arial;">
<asp:gridview id="ClientGridView"
datasourceid="ClientSource"
emptydatatext="No data available."
runat="server">
</asp:gridview>
<asp:SqlDataSource id="ClientSource"
runat="server"
ConnectionString="connection string goes here">
<SelectParameters>
<asp:QueryStringParameter Type="String" Name="phrase" QueryStringField="phrase" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
I seem to be having difficulty with asp:querystringparameter
and asp:gridview
. I have the following so far and it just returns "no data available":
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
String strGroup = Request.QueryString["group"];
switch(strGroup){
case "Clients":
ClientSource.SelectCommand = @"select client_code,
client_name from table1 where client_name = @phrase";
break;
case "Addresses":
/*different query here*/
break;
case "Matters":
/*different query here*/
break;
default:
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family:Arial;">
<asp:gridview id="ClientGridView"
datasourceid="ClientSource"
emptydatatext="No data available."
runat="server">
</asp:gridview>
<asp:SqlDataSource id="ClientSource"
runat="server"
ConnectionString="connection string goes here">
<SelectParameters>
<asp:QueryStringParameter Type="String" Name="phrase" QueryStringField="phrase" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也可以在代码后面动态绑定gridview。尝试调试您的查询是否返回任何数据。使用 SqlDataSource 有什么具体原因吗?
you can bind gridview dynamically in code behind also. Try to debug if your query is returning any data. Is there any specific reason to use SqlDataSource?