datalist中嵌套datagird,datagrid表只显示对应"序号"的行,例如:-----------------
(datalist中:)
问题序号 问题描述 责任人
1 未加盖公章 李丹
(datagrid中:)
问题序号 扣分标准 扣分
1 漏盖公章 2
1 审批环节违规 3
1 监管失利 1
-----------------
(datalist中:)
问题序号 问题描述 责任人
5 缺少审批项 王五
(datagrid中:)
问题序号 扣分标准 扣分
5 手续不全 3
5 审批流程违规 2代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SetBind();
SetBind1();
}
}
private void SetBind()//绑定datalist
{
String Con = ConfigurationSettings.AppSettings["con"];
SqlConnection con = new SqlConnection(Con);
con.Open();
SqlCommand cmd=new SqlCommand("select wt_no from wt_shezhi where xm_no='"+L5.Text.Trim()+"'", con);
SqlDataReader g=cmd.ExecuteReader();
if(g.Read())
{
a=g["wt_no"].ToString(); }
g.Close();
con.Close();
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from wt_shezhi where xm_no='"+L5.Text.Trim()+"'", con);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
this.DataList1.DataSource=ds.Tables["table1"];
this.DataList1.DataBind();
}
private void SetBind1()//绑定datagrid
{
for(int i=0;i<DataList1.Items.Count;i++)
{
DataGrid DG1=(DataGrid)this.DataList1.Items[i].FindControl("DG1");
String Con = ConfigurationSettings.AppSettings["con"];
SqlConnection con = new SqlConnection(Con);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from kf_shezhi where wt_no='"+a.Trim()+"'", con);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DG1.DataSource=ds.Tables["table1"];
DG1.DataBind(); }
}
但是每个datagrid中显示的是所有"序号"的行,不是和datalist相对应"序号"的行.
请帮忙...
(datalist中:)
问题序号 问题描述 责任人
1 未加盖公章 李丹
(datagrid中:)
问题序号 扣分标准 扣分
1 漏盖公章 2
1 审批环节违规 3
1 监管失利 1
-----------------
(datalist中:)
问题序号 问题描述 责任人
5 缺少审批项 王五
(datagrid中:)
问题序号 扣分标准 扣分
5 手续不全 3
5 审批流程违规 2代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SetBind();
SetBind1();
}
}
private void SetBind()//绑定datalist
{
String Con = ConfigurationSettings.AppSettings["con"];
SqlConnection con = new SqlConnection(Con);
con.Open();
SqlCommand cmd=new SqlCommand("select wt_no from wt_shezhi where xm_no='"+L5.Text.Trim()+"'", con);
SqlDataReader g=cmd.ExecuteReader();
if(g.Read())
{
a=g["wt_no"].ToString(); }
g.Close();
con.Close();
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from wt_shezhi where xm_no='"+L5.Text.Trim()+"'", con);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
this.DataList1.DataSource=ds.Tables["table1"];
this.DataList1.DataBind();
}
private void SetBind1()//绑定datagrid
{
for(int i=0;i<DataList1.Items.Count;i++)
{
DataGrid DG1=(DataGrid)this.DataList1.Items[i].FindControl("DG1");
String Con = ConfigurationSettings.AppSettings["con"];
SqlConnection con = new SqlConnection(Con);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from kf_shezhi where wt_no='"+a.Trim()+"'", con);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DG1.DataSource=ds.Tables["table1"];
DG1.DataBind(); }
}
但是每个datagrid中显示的是所有"序号"的行,不是和datalist相对应"序号"的行.
请帮忙...
<asp:repeater id="Repeater1" runat="server">
<ItemTemplate>
<h2><%# DataBinder.Eval(Container.DataItem,"CategoryName") %></h2>
<asp:DataGrid Runat =server DataSource ='<%# FilterDate(DataBinder.Eval(Container.DataItem,"CategoryID")) %>' ID="Datagrid1"/>
</ItemTemplate>
</asp:repeater>
在.cs里面的代码:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
//DataView DV= MyD
MyDS= new DataSet();
LoadProductDataView();
this.Repeater1.DataSource =LoadCategoryDataView();;
this.Repeater1.DataBind();
//MyDS.WriteXml("C:\\MyXML.xml");
}
} private SqlConnection CreateConnection()
{
string ConStr = System.Configuration.ConfigurationSettings.AppSettings["newConnectionString"].ToString();
MyConnection =new SqlConnection(ConStr);
return MyConnection;
}
private DataView LoadCategoryDataView()
{
string SqlStr ="select * from Categories";
MyDataAdapter = new SqlDataAdapter(SqlStr,CreateConnection());
if(CreateConnection().State ==ConnectionState.Closed)
{
CreateConnection().Open();
}
MyDataAdapter.Fill(MyDS,"Categories");
MyDV = MyDS.Tables["Categories"].DefaultView;
CreateConnection().Close();
return MyDV;
}
public DataView LoadProductDataView()
{
//MyProduct =new DataView();
string SqlStr ="select * from Products";
MyDataAdapter = new SqlDataAdapter(SqlStr,CreateConnection());
if(CreateConnection().State ==ConnectionState.Closed)
{
CreateConnection().Open();
}
//string data =MyDS.GetXml();
MyDataAdapter.Fill(MyDS,"Product");
MyProduct =MyDS.Tables["Product"].DefaultView;
CreateConnection().Close();
//Response.Write("<pre>"+ Server.HtmlEncode(data) + "</pre>");
return MyProduct;
//FilterDate(DataBinder.Eval(Container.DataItem,"CategoryID"))
} public DataView FilterDate(object CategoryID)
{
//LoadProductDataView().Count.ToString();
MyProduct.RowFilter ="CategoryID=" + Convert.ToInt32(CategoryID);
//LoadProductDataView().RowFilter="CategoryID=" + Convert.ToInt32(CategoryID);
return MyProduct; }
我这个是Repeater加DataGrid,希望对你有帮助,呵呵