试了多次也不能于DetailsView控件中,
提取某个数据项的值
Labelshow Label 只傳回空白 ,
为何呢????topic.aspx
<asp:DetailsView ID="DetailsView" runat="server" Height="50px" Width="900px" AutoGenerateRows="False" ShowHeader="false" GridLines="None" OnItemInserting="DetailsView_ItemDataBound">
<Fields>
<asp:TemplateField SortExpression="topic">
<ItemTemplate>
<div align="center"><asp:Label ID="Label1" runat="server" Text='<%# Eval("topic") %>'></asp:Label></div>
</ItemTemplate>
................................
</asp:DetailsView>
<asp:Label ID="Labelshow" runat="server"></asp:Label>
topic.aspx.csstring topic; protected void Page_Load(object sender, EventArgs e)
{
string connString = WebConfigurationManager.ConnectionStrings["AString"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from data", conn);
SqlDataReader dr = cmd.ExecuteReader();
DetailsView.DataSource = dr;
DetailsView.DataBind();
dr.Close();
conn.Close();
Labelshow.Text = topic;
}
protected void DetailsView_ItemDataBound(object sender, DetailsViewInsertEventArgs e)
{
topic = ((Label)(dDetailsView.FindControl("Label1"))).Text;
或
topic = ((Label)(dDetailsView.Rows[0].FindControl("Label1"))).Text;
}
提取某个数据项的值
Labelshow Label 只傳回空白 ,
为何呢????topic.aspx
<asp:DetailsView ID="DetailsView" runat="server" Height="50px" Width="900px" AutoGenerateRows="False" ShowHeader="false" GridLines="None" OnItemInserting="DetailsView_ItemDataBound">
<Fields>
<asp:TemplateField SortExpression="topic">
<ItemTemplate>
<div align="center"><asp:Label ID="Label1" runat="server" Text='<%# Eval("topic") %>'></asp:Label></div>
</ItemTemplate>
................................
</asp:DetailsView>
<asp:Label ID="Labelshow" runat="server"></asp:Label>
topic.aspx.csstring topic; protected void Page_Load(object sender, EventArgs e)
{
string connString = WebConfigurationManager.ConnectionStrings["AString"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from data", conn);
SqlDataReader dr = cmd.ExecuteReader();
DetailsView.DataSource = dr;
DetailsView.DataBind();
dr.Close();
conn.Close();
Labelshow.Text = topic;
}
protected void DetailsView_ItemDataBound(object sender, DetailsViewInsertEventArgs e)
{
topic = ((Label)(dDetailsView.FindControl("Label1"))).Text;
或
topic = ((Label)(dDetailsView.Rows[0].FindControl("Label1"))).Text;
}
DetailView1.Rows[i].Cells[1].Text, 若你有内嵌控件的话,用fingdcontrol就可以了
GridView控件也没有。
DataList控件有ItemDataBound事件。
protected void DetailsView_ItemDataBound(object sender, DetailsViewInsertEventArgs e)
{
topic = ((Label)(dDetailsView.FindControl("Label1"))).Text;
或
topic = ((Label)(dDetailsView.Rows[0].FindControl("Label1"))).Text;
} 这一段不会执行因为 OnItemInserting="DetailsView_ItemDataBound" 这个事件不知道什么时候会触发
{
if (this.IsPostBack)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
Label lblsex = DetailsView1.FindControl("lblsex") as Label;
}
}
}
if (DetailsView.CurrentMode == DetailsViewMode.ReadOnly)
{ Label Labelshow = DetailsView.FindControl("Label1") as Label;
}
{
Labelshow.Text = (DetailsView.FindControl("Label1") as System.Web.UI.WebControls.Label).Text;
}