......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//引用相关的命名空间
using System.Data.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
//public static readonly string connstr = ConfigurationManager.ConnectionStrings["Conner"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BingData();
//内部绑定事件
}
}
private void BingData()
{
DataContext dtContext = new DataContext(@"server=.;database=db_mobile;uid=sa;pwd=320321;");
Table<tMobleCate> mycatelist = dtContext.GetTable<tMobleCate>();
rpt_list.DataSource = mycatelist;
rpt_list.DataBind();
}
protected void rpt_style(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HiddenField hf = e.Item.FindControl("hid_fi") as HiddenField;
int cate_pkid = int.Parse(hf.Value);
DataContext dtcontent = new DataContext(@"server=.;database=db_mobile;uid=sa;pwd=320321;");
Repeater rpt_mobile = e.Item.FindControl("rpt_style") as Repeater;
if (rpt_mobile != null)
{
rpt_mobile.DataSource = dtcontent.GetTable<tMoble>()
.Where(p => p.MobileCate == cate_pkid).Select(p => p);
rpt_mobile.DataBind();
}
}
}
////定义参数表并赋值
//public int sp_user(string userid)
//{
// SqlParameter[] sqlparas = new SqlParameter[]
// {
// new SqlParameter("@PKID",SqlDbType.Int
// )
// };
// sqlparas[0].Value = userid;
// return processBy_ExecuteNonQuerys("tuser", sqlparas);
//}
////存储过程
//public int processBy_ExecuteNonQuerys(string sp_name, params SqlParameter[] sqlpare)
//{
// int row = 0;
// using (SqlConnection mycon = new SqlConnection(connstr))
// {
// SqlCommand mycom = new SqlCommand();
// mycom.CommandType = CommandType.StoredProcedure;
// mycom.CommandText = sp_name;
// mycom.Connection = mycon;
// if (sqlpare.Length > 0)
// {
// mycom.Parameters.AddRange(sqlpare);
// }
// mycon.Open();
// row = mycom.ExecuteNonQuery();
// mycon.Close();
// }
// return row;
//}
//分页的存储过程
/* create proc sp_pagelist
* (
* @pageSize int,
* @pageIndex int,
* @sumPage int out
* )
* as
* begin
* declare @notinsize int
* set @notinsize=(@pageIndex-1)*@pageSize
* select top(@pagesize)* from tweibo
* where tweibo.tweibo_pkid not in (select top(@notinsize) tweibo_pkid from tweibo)
* --计算总页数
* declare @allcount int
* set @allcount=(select count(*) from tweibo)
* --总条数/页面大小=总页数--
* set @sumPage=ceiling(cast(@allcount as float)/CAST(@pageSize as float));
* print @sumpage;
*
*
*/
}
}

浙公网安备 33010602011771号