我是asp.net的新手。我有一个checkboxlist1与一个表中的[PBN]列连接,该表只有两个值,是和否。我需要在gridview中返回数据。即使我在复选框列表中同时选择“是”和“否”,它也只会返回“否”值。如何返回两个值? 希望我说清楚了。 数据绑定
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource4" DataTextField="PBN" DataValueField="PBN" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication7
{
public partial class About : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:0)
您需要设置选中/选中的属性
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource4" DataTextField="PBN" DataValueField="PBN" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem Selected='<%# Eval("PBN") == "Yes"? true : false %>'>Yes</asp:ListItem>
<asp:ListItem Selected='<%#Eval("PBN") == "No" ? true : false %>'>No</asp:ListItem>
</asp:CheckBoxList>