More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Saturday, 3 October 2015 6:57:05 AM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 519

How to find the field values in DetailsView or GridView (ASP.NET)

1. On ASP.NET web form, add a data-bound control (any control, Label, TextBox, HyperLink, DropDown and so on) into a template field to the fields list of DetailsView or the columns list of GridView.
Code:
                                <asp:TemplateField HeaderText="FeatureLink" Visible="false">
                                    <EditItemTemplate>
                                        <asp:Label ID="LabelFeatureLink" runat="server" Text='<%# Eval("FeatureLink") %>' Visible="false" />
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="LabelFeatureLink" runat="server" Text='<%# Eval("FeatureLink") %>' Visible="false" />
                                    </ItemTemplate>
                                </asp:TemplateField>

Note the field can be hidden. It can be placed at the beginning of the fields list so it will be counted as row 0 for a DetailsView, or the beginning of the columns list so it will be counted as cell 0 for a GridView.

2. In DataBound event handler of DetailsView or GridView, find the control in the cell and then get the value of the field.
Code:
    protected void DetailsView_DataBound(object sender, EventArgs e)
    {
        string strTmp = ((Label)DetailsView5.Rows[0].Cells[1].FindControl("LabelFeatureLink")).Text;
        ...
    }

Note that for DetailsView, Cells[1] contains the value of the field while Cells[0] is the header of the field. For GridView, need to consider the header row when counting the row number.
Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.