datalist 控制每行显示数据条数的RepeatColumns属性 能否绑定数据 如何绑定数据
<%stringstrconn=ConfigurationManager.AppSettings["FLConnectionString"].ToString();str...
<%
string strconn=ConfigurationManager.AppSettings["FLConnectionString"].ToString();
string sql = "select count(*) from Picture";
int i=0;
using (SqlConnection conn = new SqlConnection(strconn))
{ conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
i = (int)cmd.ExecuteScalar();
conn.Close();
}
%> 如何把i绑定给<asp:DataList ID="DataList1" runat="server" RepeatColumns=" " DataSourceID="SqlDataSource1" DataKeyField="id" RepeatDirection="Horizontal" >中的RepeatColumns=" " 啊 展开
string strconn=ConfigurationManager.AppSettings["FLConnectionString"].ToString();
string sql = "select count(*) from Picture";
int i=0;
using (SqlConnection conn = new SqlConnection(strconn))
{ conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
i = (int)cmd.ExecuteScalar();
conn.Close();
}
%> 如何把i绑定给<asp:DataList ID="DataList1" runat="server" RepeatColumns=" " DataSourceID="SqlDataSource1" DataKeyField="id" RepeatDirection="Horizontal" >中的RepeatColumns=" " 啊 展开
2个回答
2013-07-19
展开全部
把i写成一个方法.int Geti(){string strconn=ConfigurationManager.AppSettings["FLConnectionString"].ToString();
string sql = "select count(*) from Picture";
int i=0;
using (SqlConnection conn = new SqlConnection(strconn))
{conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
i = (int)cmd.ExecuteScalar();
conn.Close();return i;
}然后这样写绑定毁纳一下告缺就能得到I了
<asp:DataList ID="DataList1" runat="server" RepeatColumns='<%#Eval(Geti())>' DataSourceID="SqlDataSource1"纤友没 DataKeyField="id" RepeatDirection="Horizontal" >}
string sql = "select count(*) from Picture";
int i=0;
using (SqlConnection conn = new SqlConnection(strconn))
{conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
i = (int)cmd.ExecuteScalar();
conn.Close();return i;
}然后这样写绑定毁纳一下告缺就能得到I了
<asp:DataList ID="DataList1" runat="server" RepeatColumns='<%#Eval(Geti())>' DataSourceID="SqlDataSource1"纤友没 DataKeyField="id" RepeatDirection="Horizontal" >}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-19
展开全部
恐怕凯族不能。我的信数意思是你不得不人为的代码修改(比如在点击一个按滑孙首钮的时候写上:Repeater1.RepeatColumns= XX);请参考这个: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.repeatcolumns.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询