页面1:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="AuthorCode" HeaderText="AuthorCode"
SortExpression="AuthorCode" />
<asp:BoundField DataField="AuthorName" HeaderText="AuthorName"
SortExpression="AuthorName" />
<asp:BoundField DataField="AuthorLevel" HeaderText="AuthorLevel"
SortExpression="AuthorLevel" />
<asp:HyperLinkField AccessibleHeaderText="编辑"
DataNavigateUrlFields="ForbidOpers"
DataNavigateUrlFormatString="Default3.aspx?id={0}"
HeaderText="编辑" Text="编辑" InsertVisible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DCProjectDbConnectionString%>"
SelectCommand="SELECT [AuthorCode], [AuthorName], [AuthorLevel], [ForbidOpers] FROM [CF_PM_AuthorType]">
</asp:SqlDataSource>页面2: <asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="OperName"
DataValueField="OperName">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DCProjectDbConnectionString %>"
SelectCommand="SELECT [OperName], [OperCode] FROM [CF_PM_OperType]">
</asp:SqlDataSource>
数据表1:CF_PM_AuthorType 和 数据表2:CF_PM_OperType 之间存在关系(CF_PM_AuthorType中字段ForbidOpers值为多个,其中用逗号分隔,例如:32783,32784 ;CF_PM_OperType中字段 OperCode值为一个,分别为32783,32784)
要实现的功能:页面2读取出CF_PM_OperType数据表2中的所有记录,并以复选框显示,当页面1中传递数据表1中ForbidOpers字段多个值到页面2时,页面2中读取出来的复选框磨人勾选
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="AuthorCode" HeaderText="AuthorCode"
SortExpression="AuthorCode" />
<asp:BoundField DataField="AuthorName" HeaderText="AuthorName"
SortExpression="AuthorName" />
<asp:BoundField DataField="AuthorLevel" HeaderText="AuthorLevel"
SortExpression="AuthorLevel" />
<asp:HyperLinkField AccessibleHeaderText="编辑"
DataNavigateUrlFields="ForbidOpers"
DataNavigateUrlFormatString="Default3.aspx?id={0}"
HeaderText="编辑" Text="编辑" InsertVisible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DCProjectDbConnectionString%>"
SelectCommand="SELECT [AuthorCode], [AuthorName], [AuthorLevel], [ForbidOpers] FROM [CF_PM_AuthorType]">
</asp:SqlDataSource>页面2: <asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="OperName"
DataValueField="OperName">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DCProjectDbConnectionString %>"
SelectCommand="SELECT [OperName], [OperCode] FROM [CF_PM_OperType]">
</asp:SqlDataSource>
数据表1:CF_PM_AuthorType 和 数据表2:CF_PM_OperType 之间存在关系(CF_PM_AuthorType中字段ForbidOpers值为多个,其中用逗号分隔,例如:32783,32784 ;CF_PM_OperType中字段 OperCode值为一个,分别为32783,32784)
要实现的功能:页面2读取出CF_PM_OperType数据表2中的所有记录,并以复选框显示,当页面1中传递数据表1中ForbidOpers字段多个值到页面2时,页面2中读取出来的复选框磨人勾选
解决方案 »
- 请为可以在函数内遍历控件吗?
- 疑问:把图片以字节流形式存放在SQL SERVER 中,改如何读取?
- 在线急求:根据连接地址下载网站上文本文件并把内容显示在TextBox中(孟哥,思归,小山及各位星爷及同行门帮助,结贴献份)
- 求关于Spreadsheet的正确标识的方法(急!!)
- 请教大家一个微软PetShow例子的问题
- 对asp文件中的数据库连接字段加密?
- 请问怎样在css文件里定义<img>
- 两个 List 的对比
- Textbox控件设置只读或把enabled=false,提交时值会丢失>??????
- 如何在asp.net页面中保存变量?是不是只能用session,类的静态变量可以吗??
- asp.net无法调试
- 微软的AjaxTookit太占空间了
下面是我写的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Configuration;
using System.Data;
public partial class Default3 : System.Web.UI.Page
{
public string strArrays = null;
public int j;
protected void Page_Load(object sender, EventArgs e)
{
String connectionString = ConfigurationManager.ConnectionStrings["DCProjectDbConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
String id = Request.QueryString["id"];
String[] array=id.Split(',');
string sql = "";
for (j = 0; j < array.Length; j++)
{
sql = "select OperName from CF_PM_OperType where OperCode ='" + array[j] + "'";
} SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string strTerm = dr["OperCode"].ToString();
string[] strTerms = strTerm.Split(',');
foreach (ListItem lItem in CheckBoxList1.Items)
{
for (int i = 0; i < strTerms.Length; i++)
{
if (lItem.Value == strTerms[i])
{
lItem.Selected = true;
break;//加上这个
}
}
}
}
dr.Close();
con.Close();
}
}
foreach (ListItem li in CheckBoxList1.Items)
{
foreach(string s in str.Split(','))
{ if (li.Value.Equals(s))
li.Selected = true;
}
}
或使用List<string>判断是否contains(li.Value)