Solved

Gridview looping through records in aaspx page...

Posted on 2012-04-05
3
286 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
Comment Utility
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
Comment Utility
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
Comment Utility
thats correct it is the position of the column in the row
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

14 Experts available now in Live!

Get 1:1 Help Now