Solved

Gridview looping through records in aaspx page...

Posted on 2012-04-05
3
303 Views
Last Modified: 2012-06-27
Hi,

On my aspx page I'm binding datasource to a datagrid and set the AutoGenerateColumns="false" so I could construct the column as i wish. This what I done:

<Columns>
            <asp:TemplateField HeaderText="Exam Sit" runat="server">
                             <ItemTemplate>
                                 <asp:CheckBox  ID="chkExamsit" runat="server" Text="" />
                            </ItemTemplate>
             </asp:TemplateField>
            <asp:TemplateField HeaderText="Exam Code" runat="server">
                             <ItemTemplate>
                                <asp:Label ID="lblExamCode" runat="server" Text='<%# ((ExamsDisplay)Container.DataItem).ExamCode %>'></asp:Label>
                            </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="Description" runat="server">
                             <ItemTemplate>
                                <asp:Label ID="lblDescription" runat="server" Text='<%# ((ExamsDisplay)Container.DataItem).Description %>'></asp:Label>
                            </ItemTemplate>
            </asp:TemplateField>
   
             <asp:TemplateField HeaderText="Duration" runat="server">
                             <ItemTemplate>
                                <asp:Label ID="lblDuration" runat="server" Text='<%# ((ExamsDisplay)Container.DataItem).Duration %>'></asp:Label>
                            </ItemTemplate>
            </asp:TemplateField>
           
             <asp:TemplateField HeaderText="Requested Date" runat="server">
                             <ItemTemplate>
                                <asp:DropDownList ID="ddlRequestedDate" DataSourceID="xmlExamLevelDates" DataMember="ExamLevelDate" DataTextField="Date"  Width="100" runat="server" > </asp:DropDownList>
                            </ItemTemplate>
            </asp:TemplateField>
           
             <asp:TemplateField HeaderText="Requested Venue" runat="server">
                             <ItemTemplate>
                                <asp:DropDownList ID="ddlRequestedVenue" Width="100" runat="server" > </asp:DropDownList>
                            </ItemTemplate>
            </asp:TemplateField>
         
           
             <asp:TemplateField HeaderText="Exam Result" runat="server">
                             <ItemTemplate>
                                <asp:TextBox ID="txtExamResult" runat="server" Width="75" Text='<%# ((ExamsDisplay)Container.DataItem).Result %>'></asp:TextBox>
                            </ItemTemplate>
            </asp:TemplateField>
   
             <asp:TemplateField HeaderText="Confirmed Date" runat="server">
                             <ItemTemplate>
                                <asp:TextBox ID="txtConfirmedDate" runat="server" CssClass="datepicker" Text='<%# ((ExamsDisplay)Container.DataItem).ConfirmedExamDate %>'></asp:TextBox>
                            </ItemTemplate>
            </asp:TemplateField>
   
             <asp:TemplateField HeaderText="Confirmed Venue" runat="server">
                             <ItemTemplate>
                                <asp:DropDownList ID="ddlConfirmedVenue" Width="100" runat="server" > </asp:DropDownList>
                            </ItemTemplate>
            </asp:TemplateField>

Now I want this data to be sent it to a data store for storage. How do I loop through the records in a gridview control that has template column rather than bound column.

Can someone help me do this plaese.

Thanks!

Regards - Raj
0
Comment
Question by:ube100
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 37820751
hi

each time you have to change the data type for each coloum

for example:
    Dim chkExamsit As CheckBox = CType(GridView1.Rows(i).Cells(0).FindControl("chkExamsit"), CheckBox)
    Dim lblExamCodeAs label= CType(GridView1.Rows(i).Cells(1).FindControl("lblExamCode"), label)
.
.....



make a for statement and search each record
Ex:
  For i As Integer = 0 To GridView1.Rows.Count - 1
                Dim chkDelete As CheckBox = CType(GridView1.Rows(i).Cells(0).FindControl("chkContractor"), CheckBox)
                If Not chkDelete Is Nothing Then
                    If chkDelete.Checked Then

                     

                       ' do what u want

                           

                        End If
                    End If
                End If
            Next
0
 

Author Comment

by:ube100
ID: 37820785
Hi,

  Dim chkDelete As CheckBox = CType(GridView1.Rows(i).Cells(0).FindControl

What is Cells(0) represent here? I believe, the position of the column in the row?
0
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 500 total points
ID: 37822970
thats correct it is the position of the column in the row
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question