主题:请教接值问题
请教各位:
我在AlternatingItemTemplate里是可以正确接到值的,
而我在ItemTemplate里,我想要用OnItemDataBound把值传到里头的Label!
我要如何把我select出来的值传到Repeater里的Label呢?
谢谢各位:-)
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
string DSN = ConfigurationSettings.AppSettings["MDBPEAK"];
string strSQL = "SELECT * FROM PCategory";
OleDbConnection Cn = new OleDbConnection(DSN);
OleDbDataAdapter Cmd = new OleDbDataAdapter(strSQL, Cn);
DataSet ds = new DataSet();
Cmd.Fill(ds, "PCategory");
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();
string GetCAId = Convert.ToString(ds.Tables[0].Rows[0][0]);
string GetSortC = Convert.ToString(ds.Tables[0].Rows[0][1]);
string GetCategoryName = Convert.ToString(ds.Tables[0].Rows[0][2]);
}
}
private void Repeater1_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
Label lb1 = (Label)e.Item.FindControl("lblItem1");
Label lb2 = (Label)e.Item.FindControl("lblItem2");
Label lb3 = (Label)e.Item.FindControl("lblItem3");
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (lb1 != null) lb1.Text = Convert.ToString(请教如何接GetCAId值);
if (lb2 != null) lb2.Text = Convert.ToString(请教如何接GetSortC值);
if (lb3 != null) lb3.Text = Convert.ToString(请教如何接GetCategoryName值);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>PCategory</title>
</head>
<body>
<h3>PCategory</h3>
<form id="form1" runat="server">
<asp:Repeater id="Repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound">
<HeaderTemplate />
<ItemTemplate>
INSERT INTO PCategory (CId,SortC,CategoryName) VALUES ('<asp:Label id="lblItem1" runat="server" />','<asp:Label id="lblItem2" runat="server" />','<asp:Label id="lblItem3" runat="server" />')<br>
</ItemTemplate>
<AlternatingItemTemplate>
INSERT INTO PCategory (CId,SortC,CategoryName) VALUES ('<%# DataBinder.Eval(Container.DataItem, "CAId") %>','<%# DataBinder.Eval(Container.DataItem, "SortC") %>','<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>')<br>
</AlternatingItemTemplate>
<FooterTemplate />
</asp:Repeater>
</form>
</body>
</html>
我在AlternatingItemTemplate里是可以正确接到值的,
而我在ItemTemplate里,我想要用OnItemDataBound把值传到里头的Label!
我要如何把我select出来的值传到Repeater里的Label呢?
谢谢各位:-)
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
string DSN = ConfigurationSettings.AppSettings["MDBPEAK"];
string strSQL = "SELECT * FROM PCategory";
OleDbConnection Cn = new OleDbConnection(DSN);
OleDbDataAdapter Cmd = new OleDbDataAdapter(strSQL, Cn);
DataSet ds = new DataSet();
Cmd.Fill(ds, "PCategory");
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();
string GetCAId = Convert.ToString(ds.Tables[0].Rows[0][0]);
string GetSortC = Convert.ToString(ds.Tables[0].Rows[0][1]);
string GetCategoryName = Convert.ToString(ds.Tables[0].Rows[0][2]);
}
}
private void Repeater1_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
Label lb1 = (Label)e.Item.FindControl("lblItem1");
Label lb2 = (Label)e.Item.FindControl("lblItem2");
Label lb3 = (Label)e.Item.FindControl("lblItem3");
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (lb1 != null) lb1.Text = Convert.ToString(请教如何接GetCAId值);
if (lb2 != null) lb2.Text = Convert.ToString(请教如何接GetSortC值);
if (lb3 != null) lb3.Text = Convert.ToString(请教如何接GetCategoryName值);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>PCategory</title>
</head>
<body>
<h3>PCategory</h3>
<form id="form1" runat="server">
<asp:Repeater id="Repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound">
<HeaderTemplate />
<ItemTemplate>
INSERT INTO PCategory (CId,SortC,CategoryName) VALUES ('<asp:Label id="lblItem1" runat="server" />','<asp:Label id="lblItem2" runat="server" />','<asp:Label id="lblItem3" runat="server" />')<br>
</ItemTemplate>
<AlternatingItemTemplate>
INSERT INTO PCategory (CId,SortC,CategoryName) VALUES ('<%# DataBinder.Eval(Container.DataItem, "CAId") %>','<%# DataBinder.Eval(Container.DataItem, "SortC") %>','<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>')<br>
</AlternatingItemTemplate>
<FooterTemplate />
</asp:Repeater>
</form>
</body>
</html>