Solved

Gridview looping through records in aaspx page...

Posted on 2012-04-05
3
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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