CheckBoxList 绑定不到数据的问题,问题搞了我两周时间了,好心人救命!
这个是前台:<wp:TabPage runat="server" Caption="页面文件" ID="tabPage0">
<div style="overflow:scroll; height:420px;" id="templatepage">
<wp:CheckBoxList ID="HtmlList" runat="server" RepeatColumns="2" DataTextField="FieldText" DataValueField="FileName">
</wp:CheckBoxList>
</div>
<div style="text-align:right; padding-top:10px;">
<input type="checkbox" id="chkall" name="chkall" onclick="Check(this.form);" />选择全部
<wp:Button ID="btnCreate" runat="server" Text="按选中模板文件生成页面" OnClick="btnCreate_Click" />
<wp:Button ID="btnDelete" runat="server" Text="删除选中模板文件" OnClick="btnDelete_Click" />
<button onclick="GotoUrl('sys_templatevar')" class="ManagerButton">
<img src="../../images/btnimg/submit.gif" />模板变量列表
</button>
</div>
</wp:TabPage>
后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WP.Logic;
using WP.Common;
namespace WP.Web.admin.templatemanager
{
public partial class sys_templatefiles : AdminPage
{
private string TemplateDir = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(WebUtils.GetString("path")!="")
TemplateDir = WebUtils.GetString("path");
BindGridView();
}
}
private void BindGridView()
{
string templatename = WebUtils.GetString("path");
HtmlList.DataSource = Templates.GetTemplateFiles(templatename, "*.htm|*.config|*.html");
// HtmlList.DataTextField = "FieldText";
// HtmlList.DataValueField = "FileName";
HtmlList.DataBind();
CssList.DataSource = Templates.GetTemplateFiles(templatename, "*.css");
CssList.DataBind();
JSList.DataSource = Templates.GetTemplateFiles(templatename, "*.js");
JSList.DataBind();
}
protected void btnCreate_Click(object sender, EventArgs e)
{
int count = 0;
for (int i = 0; i < HtmlList.Items.Count; i++)//不知为什么conut的值总为0,导致后面的操作不能实现 {
if (HtmlList.Items[i].Selected)
{
Templates.CreateOneTemplate(HtmlList.Items[i].Value, TemplateDir);
count += 1;
}
}
RegisterStartupScript("PAGE", "<script>alert('一共更新了"+count.ToString()+"个模板文件。');</script>");
}
protected void btnDelete_Click(object sender, EventArgs e)
{
BindGridView();
}
}
}
--------------------编程问答-------------------- // HtmlList.DataTextField = "FieldText";
// HtmlList.DataValueField = "FileName";
你把绑定的代码都注释了,HtmList的Item.count当然是空的啊 --------------------编程问答-------------------- wp:CheckBoxList 是个什么东西,检查下它里面的代码是否正确 --------------------编程问答-------------------- 看到肿么长的代码就眼晕 --------------------编程问答-------------------- happy09li:
那个绑定的代码我当时也都加了上去,但后台还是一个样的问题
--------------------编程问答-------------------- nfclass
wp:CheckBoxList 是个重写的checkBoxList控件,那个wp是自己的语法 --------------------编程问答-------------------- wpCheckBoxList类名称 x = tabPage0.FindControl("HtmlList") as wpCheckBoxList类名称;
for (int i = 0; i < x.Items.Count; i++)/ --------------------编程问答-------------------- 高手,我按照你的方法还是取到的x.Items.Count=0 --------------------编程问答-------------------- 把你的那个自定义控件发到我的信箱测试下
amxh@21cn.com --------------------编程问答-------------------- HtmlList.Items.Count为0,如果你取到的templatename没有值呢?
string templatename = WebUtils.GetString("path");
HtmlList.Items.Count会不会为0??
补充:.NET技术 , ASP.NET