试了多次也不能于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; 
    } 

解决方案 »

  1.   

    detaileview 一共就2列,行数也是固定的,和你要显示的数量一样,你只要写
    DetailView1.Rows[i].Cells[1].Text, 若你有内嵌控件的话,用fingdcontrol就可以了
      

  2.   

    DetailsView没有ItemDataBound事件吧?
    GridView控件也没有。
    DataList控件有ItemDataBound事件。
      

  3.   

    可不可以提供 code , 不太明白 ....string topic = DetailView1.Rows[i].Cells[1].Text; ???
      

  4.   

    我估计
    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" 这个事件不知道什么时候会触发
      

  5.   

    protected void DetailsView1_PreRender(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
                {
                    
                    Label lblsex = DetailsView1.FindControl("lblsex") as Label;
                }
            }
        }
      

  6.   

    還是不行
                
    if (DetailsView.CurrentMode == DetailsViewMode.ReadOnly)
                {                Label Labelshow = DetailsView.FindControl("Label1") as Label;
                }
      

  7.   

    我在DetailsView_DataBound事件中测试是可以取到值的  protected void DetailsView_DataBound(object sender, EventArgs e)
        {
            Labelshow.Text = (DetailsView.FindControl("Label1") as System.Web.UI.WebControls.Label).Text;
        }