当前位置:编程学习 > C#/ASP.NET >>

DetailsView 里取控件值的问题

       string id = DetailsView1.DataKey.Value.ToString();

       string title = ((TextBox)(DetailsView1.Rows[1].Cells[1].Controls[0])).Text.ToString();
       string content = ((TextBox)(DetailsView1.Rows[2].Cells[1].Controls[0])).Text.ToString();
       string time = ((TextBox)(DetailsView1.Rows[3].Cells[1].Controls[0])).Text.ToString();
      string author=((TextBox)(DetailsView1.Rows[4].Cells[1].Controls[0])).Text.ToString();


第4个 author里面还有个我增加的 更新按钮linkbutton  这里就提示出错 
有什么办法 只取这个textbox啊 ((TextBox)(DetailsView1.Rows[4].Cells[1].Controls[0])).Text.ToString();
这句不是只取第一个控件吗 怎么取到了 linkbutton
源代码里是这样的

 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="news_id" OnItemUpdating="DetailsView1_ItemUpdating">
            <Fields>
                <asp:BoundField DataField="news_id" />
                <asp:BoundField DataField="news_title" />
                <asp:BoundField DataField="news_content" />
                <asp:BoundField DataField="news_time" />
                <asp:TemplateField>
                   <EditItemTemplate>
              <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("news_author") %>'></asp:TextBox><br />
              <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update">LinkButton</asp:LinkButton>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("news_author") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("news_author") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Fields>
       
        </asp:DetailsView>

请高手指教下 谢谢  --------------------编程问答-------------------- --------------------编程问答-------------------- 還是用FindCrol好用。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,