repeater的一点困惑
using System;using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBind(5,"stu");
}
}
protected void DataBind(int num,string rptname)
{
SqlConnection con = new SqlConnection(@"Data Source=bbe1e6eeea28453\sqlexpress;Initial Catalog=web10;Integrated Security=True;Pooling=False");
string str="select top num * from student";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
da.Fill(ds);
rptname.DataSource = ds.Tables[0].DefaultView;
rptname.DataBind();
}
}
string rptname是指repeater空间的 ID
调试的时候 说 string没有包含 DataSource,DataBind的定义
是在web页面!!!!!
应该使用repeater r=this._Default.findcontrol(“rptname”)as repeater还是repeater r=this.form1.findcontrol(“rptname”)as repeater?或者是其他?
--------------------编程问答--------------------
--------------------编程问答-------------------- 我想多次调用这个函数来实现绑定!!!! --------------------编程问答-------------------- protected void DataBind(int num,string rptname)
<asp:Repeater ID="rptname" runat="server">
<ItemTemplate>
内容
</ItemTemplate>
</asp:Repeater>
传得参数是string类型的
比如时string rptname="ZZZZ"
你不能"ZZZZ".DataSource = ds.Tables[0].DefaultView;
"ZZZZ".rptname.DataBind();
还有,你传入的参数num在sql里边也不能这样写string str="select top num * from student";
写成 string str="select top " + num + " * from student";
--------------------编程问答-------------------- 错误很明显,rptname 参数不可能是string类型 lz是想传个repeater控件名进来吧,把reptname前的参数类型改成
如下:
protected void DataBind(int num,System.Web.UI.WebControls.Repeater rptname)
但是看来Repeater本身就是页面中的,不知lz为何再找个参数传进来是何意??
还有就是lz的SQL语句也有错呀
要把 string str="select top num * from student";
改写成string str="select top " + num + " * from student"; 才可以呀
--------------------编程问答-------------------- protected void DataBind(int num,Repeater rptname)
{
SqlConnection con = new SqlConnection(@"Data Source=bbe1e6eeea28453\sqlexpress;Initial Catalog=web10;Integrated Security=True;Pooling=False");
string str="select top num * from student";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
da.Fill(ds);
rptname.DataSource = ds.Tables[0].DefaultView;
rptname.DataBind();
} --------------------编程问答-------------------- 查询命令语句都错了
string str="select top " + num + " * from student"; --------------------编程问答-------------------- 是的,是有报错,但我现在想调用那个函数,用什么方法?
补充:.NET技术 , ASP.NET