Solved

Gridview looping through records in aaspx page...

Posted on 2012-04-05
3
296 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now