我现在只是写好了搜索功能,在代码的最下面我加了一个搜索btnserch_Click。但是不能很好的和排序结合在一起。需求在那个图片上写了
下面是排序的程序: protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Request.QueryString["sn"]) && string.IsNullOrEmpty(Request.QueryString["game"]))
{
BindGrid_null();
} if (!string.IsNullOrEmpty(Request.QueryString["sn"]))
{
BindGrid_sn(Request.QueryString["sn"]);
} if (!string.IsNullOrEmpty(Request.QueryString["game"]))
{
BindGrid_game(Request.QueryString["game"]);
} if (tserch.Text.Trim() != "")
{
}
} private void BindGrid_null()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); string cmd1 = "select game,sn from [order]";
SqlDataAdapter sda1 = new SqlDataAdapter(cmd1, con);
DataSet ds1 = new DataSet();
con.Open();
sda1.Fill(ds1, "order");
DataTable dt = ds1.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
}
private void BindGrid_game(string game)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); string cmd = string.Empty; if (string.IsNullOrEmpty(game))
cmd = "select game,sn from [order]";
else
cmd = "select game,sn from [order] where game= '" + game + "'union all select game,sn from [order] where game <> '" + game + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
con.Open();
sda.Fill(ds, "order");
DataTable dt = ds.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
} private void BindGrid_sn(string sn)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); string cmd = string.Empty; if (string.IsNullOrEmpty(sn))
cmd = "select game,sn from [order]";
else
cmd = "select game,sn from [order] where sn= '" + sn + "'union all select game,sn from [order] where sn <> '" + sn + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
con.Open();
sda.Fill(ds, "order");
DataTable dt = ds.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
}
protected void btnserch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
string box = tserch.Text.ToString(); string cmd = "select game,sn from [order] where game='" + box + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet(); con.Open();
sda.Fill(ds, "order");
DataTable dt = ds.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
}
下面是排序的程序: protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Request.QueryString["sn"]) && string.IsNullOrEmpty(Request.QueryString["game"]))
{
BindGrid_null();
} if (!string.IsNullOrEmpty(Request.QueryString["sn"]))
{
BindGrid_sn(Request.QueryString["sn"]);
} if (!string.IsNullOrEmpty(Request.QueryString["game"]))
{
BindGrid_game(Request.QueryString["game"]);
} if (tserch.Text.Trim() != "")
{
}
} private void BindGrid_null()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); string cmd1 = "select game,sn from [order]";
SqlDataAdapter sda1 = new SqlDataAdapter(cmd1, con);
DataSet ds1 = new DataSet();
con.Open();
sda1.Fill(ds1, "order");
DataTable dt = ds1.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
}
private void BindGrid_game(string game)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); string cmd = string.Empty; if (string.IsNullOrEmpty(game))
cmd = "select game,sn from [order]";
else
cmd = "select game,sn from [order] where game= '" + game + "'union all select game,sn from [order] where game <> '" + game + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
con.Open();
sda.Fill(ds, "order");
DataTable dt = ds.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
} private void BindGrid_sn(string sn)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); string cmd = string.Empty; if (string.IsNullOrEmpty(sn))
cmd = "select game,sn from [order]";
else
cmd = "select game,sn from [order] where sn= '" + sn + "'union all select game,sn from [order] where sn <> '" + sn + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
con.Open();
sda.Fill(ds, "order");
DataTable dt = ds.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
}
protected void btnserch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
string box = tserch.Text.ToString(); string cmd = "select game,sn from [order] where game='" + box + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet(); con.Open();
sda.Fill(ds, "order");
DataTable dt = ds.Tables["order"];
con.Close(); foreach (DataRow row in dt.Rows)
{
Response.Write("<table width=250 height=20 border=0 cellspacing=0 cellpadding=0><tr><td width=100><a href=index.aspx?game=" + row["game"] + ">" + (row["game"]) + "</a></td><td width=150><a href=index.aspx?sn=" + row["sn"] + ">" + (row["sn"]) + "</a></td></tr></table>");
}
}
解决方案 »
- 如果从数据库里读到的图片路径为空,怎样全局设置它为一个缺省图片
- 一个网站的log如何设置,请教
- Entity Framework的项目创建
- win7 iis7.5下发布 报BLL的引用读不进来
- 一个中型网站 我用c#或vb直接生成html行不行 不用任何控件
- 网页视频播放声音与图象不同步问题
- 高分求自定义报表控件
- 带dll的aspx如何发布?
- 水晶报表的问题“未将对象引用到对象的实例”
- 全文检索的问题:现在存放全文检索索引的文件夹已经有好几个G了,如何压缩索引文件且不影响检索?在线等待,好了就结分
- windows mobile手机上的IE问题
- 利用dropdownlist 实现分页跳转时 如何保持原来选中的item 不变?(解决后马上给分!!!!!!!!!)
private void BindGrid_game(string game)不是都在这里面吗
ds.Tables[0].DefaultView.Sort = "UpdateTime Desc";这样排序
你没有排序