Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6059865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:45:36+00:00 2026-05-23T08:45:36+00:00

In my asp.net + VB Gridview, I had bind several column from datatable into

  • 0

In my asp.net + VB Gridview, I had bind several column from datatable into one single column of the gridview.

Sample Screen

But I have no idea how to get those value when doing RowEditing & RowUpdating. Please help. Thanks.

The following is the VB code:

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
    'Set the edit index.
    Gridview1.EditIndex = e.NewEditIndex        
    'Bind data to the GridView control.
    BindData()
End Sub

Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
    'Reset the edit index.
    Gridview1.EditIndex = -1
    'Bind data to the GridView control.
    BindData()
End Sub

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    'Retrieve the table from the session object.
    Dim dt = CType(Session("dt"), DataTable)

    'Update the values.
    Dim row = Gridview1.Rows(e.RowIndex)

    .............................

    'Reset the edit index.
    Gridview1.EditIndex = -1

    'Bind data to the GridView control.
    BindData()
End Sub

The following is the aspx code:

Private Sub CreateDataTable() 

    Dim cmd As New System.Data.SqlClient.SqlCommand 
    Dim sql As String 
    Dim reader As System.Data.SqlClient.SqlDataReader 
    Dim cmd3 As New System.Data.SqlClient.SqlCommand 
    Dim sql3 As String 
    Dim reader3 As System.Data.SqlClient.SqlDataReader 

    Using conn2 As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("XXXonnectionString").ConnectionString) 
        conn2.Open() 
        cmd.Connection = conn2 

        sql = "SET DATEFORMAT dmy;SELECT * FROM XXXX " 
        cmd.CommandText = sql 
        reader = cmd.ExecuteReader() 

        Dim TempStaffKey As Integer 
        Dim TempPostKey As Integer 
        Dim TempShiftDate As DateTime 
        Dim TempStartTime As DateTime 
        Dim TempEndTime As DateTime 
        Dim TempSL As String 
        Dim TempRosterKey As Integer 
        Dim TempVL As String 
        Dim TempML As String 
        Dim TempPH As String 
        Dim TempAPH As String 
        Dim TempTOIL As String 
        Dim TempOthers As String 
        Dim TempShiftType As Integer 
        Dim TempSubmittedBy As Integer 

        Dim dt As New DataTable() 
        dt.Columns.Add(New DataColumn("StaffName", GetType(String))) 
        dt.Columns.Add(New DataColumn("PostCode", GetType(String))) 
        dt.Columns.Add(New DataColumn("StaffKey", GetType(Int32))) 
        dt.Columns.Add(New DataColumn("PostKey", GetType(Int32))) 

        'Monday 
        dt.Columns.Add(New DataColumn("Col1_RosterKey", GetType(Int32))) 
        dt.Columns.Add(New DataColumn("Col1_ShiftDate", GetType(DateTime))) 
        dt.Columns.Add(New DataColumn("Col1_StartTime", GetType(DateTime))) 
        dt.Columns.Add(New DataColumn("Col1_EndTime", GetType(DateTime))) 
        dt.Columns.Add(New DataColumn("Col1_SL", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_VL", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_ML", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_PH", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_APH", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_TOIL", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_Others", GetType(String))) 
        dt.Columns.Add(New DataColumn("Col1_ShiftType", GetType(Int32))) 
        dt.Columns.Add(New DataColumn("Col1_SubmittedBy", GetType(Int32))) 

        Dim dr As DataRow 

        While reader.Read()    '---For each row 

            g_TempStaffKey = "0" 
            TempStaffKey = reader("staff_key")   'will not null 
            g_selectstaffkey = TempStaffKey 
            g_selectpostkey = reader("post_key") 
            g_selectstaffname = RTrim(reader("name_eng")) 
            g_selectpostcode = RTrim(reader("post_code")) 

            Using conn3 As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("XXXConnectionString").ConnectionString) 
                conn3.Open() 
                cmd3.Connection = conn3 
                sql3 = "SET DATEFORMAT dmy;SELECT * FROM xxx" 
                cmd3.CommandText = sql3 
                reader3 = cmd3.ExecuteReader() 
                If reader3.Read() Then 

                    TempStaffKey = reader3("staff_key") 

                    If Not IsDBNull(reader3("post_key")) Then 
                        TempPostKey = reader3("post_key") 
                    End If 

                    If Not IsDBNull(reader3("roster_key")) Then 
                        TempRosterKey = reader3("roster_key") 
                    End If 

                    If Not IsDBNull(reader3("shift_date")) Then 
                        TempShiftDate = Format(reader3("shift_date"), "dd/MM/yyyy") 
                    End If 

                    If Not IsDBNull(reader3("start_time")) Then 
                        TempStartTime = Format(reader3("start_time"), "HH:mm") 
                    End If 

                    If Not IsDBNull(reader3("end_time")) Then 
                        TempEndTime = Format(reader3("end_time"), "HH:mm") 
                    End If 

                    If Not IsDBNull(reader3("SL")) Then 
                        TempSL = reader3("SL") 
                    Else 
                        TempSL = "0" 
                    End If 

                    If Not IsDBNull(reader3("VL")) Then 
                        TempVL = reader3("VL") 
                    Else 
                        TempVL = "0" 
                    End If 

                    If Not IsDBNull(reader3("ML")) Then 
                        TempML = reader3("ML") 
                    Else 
                        TempML = "0" 
                    End If 

                    If Not IsDBNull(reader3("PH")) Then 
                        TempPH = reader3("PH") 
                    Else 
                        TempPH = "0" 
                    End If 

                    If Not IsDBNull(reader3("APH")) Then 
                        TempAPH = reader3("APH") 
                    Else 
                        TempAPH = "0" 
                    End If 

                    If Not IsDBNull(reader3("TOIL")) Then 
                        TempTOIL = reader3("TOIL") 
                    Else 
                        TempTOIL = "0" 
                    End If 

                    If Not IsDBNull(reader3("Others")) Then 
                        TempOthers = reader3("Others") 
                    Else 
                        TempOthers = "null" 
                    End If 

                    If Not IsDBNull(reader3("shift_type")) Then 
                        TempShiftType = reader3("shift_type") 
                    End If 

                    If Not IsDBNull(reader3("submitted_by")) Then 
                        TempSubmittedBy = reader3("submitted_by") 
                    End If 

                    dr = dt.NewRow() 

                    dr("StaffName") = g_selectstaffname 
                    dr("PostCode") = g_selectpostcode 
                    dr("StaffKey") = TempStaffKey 
                    dr("PostKey") = TempPostKey 

                    'Col1 
                    If TempShiftDate = g_header1 Then 
                        dr("Col1_RosterKey") = TempRosterKey 
                        dr("Col1_ShiftDate") = TempShiftDate 
                        dr("Col1_StartTime") = TempStartTime 


                        dr("Col1_EndTime") = TempEndTime 
                        dr("Col1_SL") = TempSL 
                        dr("Col1_VL") = TempVL 
                        dr("Col1_ML") = TempML 
                        dr("Col1_PH") = TempPH 
                        dr("Col1_APH") = TempAPH 
                        dr("Col1_TOIL") = TempTOIL 
                        dr("Col1_Others") = TempOthers 
                        dr("Col1_ShiftType") = TempShiftType 
                        dr("Col1_SubmittedBy") = TempSubmittedBy 
                    End If 

                End If 
................. 

                conn3.Close() 
                reader3.Close() 
            End Using 
        End While 

        Gridview1.DataSource = dt 
        Gridview1.DataBind() 

        'Persist the table in the Session object. 
        Session("dt") = dt 

        reader.Close() 

    End Using 

End Sub



<%@ Page Title="Input" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="sd210.aspx.vb" Inherits="sd210" ValidateRequest="false"%>
<%@ Register Assembly="TimePicker" Namespace="MKB.TimePicker" TagPrefix="MKB" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CPH1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:hris_shiftdutyConnectionString %>"SelectCommand="set language english; SET DATEFORMAT dmy; select * from troster">
</asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:hris_shiftdutyConnectionString %>"
    SelectCommand="set language english; select * from tshift_type">
</asp:SqlDataSource>
<asp:Label ID="lb_login_name" runat="server"  Visible="false"  ></asp:Label>
<asp:Label ID="lb_login_staff_key" runat="server"  Visible="false"  ></asp:Label>
<asp:Label ID="lb_login_post_key" runat="server"  Visible="false"  ></asp:Label>
<asp:Label ID="lb_test" runat="server"  Visible="false"  ></asp:Label>

<asp:GridView ID="Gridview1" runat="server"
AutoGenerateColumns = "false" Font-Names = "Arial"
AutoGenerateEditButton="True" 
Font-Size = "10pt" AlternatingRowStyle-BackColor = "#C2D69B" 
AllowPaging ="true"  
PageSize = "20" Caption = "" 
onrowdatabound="GridView1_RowDataBound"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating"
OnPageIndexChanging="GridView1_PageIndexChanging">

<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<Columns>
 <asp:BoundField DataField = "PostCode" HeaderText = "Post"  ReadOnly ="true" />
 <asp:BoundField DataField = "StaffName" HeaderText = "Name" ReadOnly ="true"  />

<asp:TemplateField HeaderText="Working<br>Time">
<ItemTemplate>
<asp:Label ID="lb1_rosterkey"  runat="server"  Text='<%#DataBinder.Eval(Container.DataItem, "Col1_RosterKey")%>'  Visible ="false" ></asp:Label>
<asp:BoundField DataField = "Col1_ShiftType" />
<MKB:TimeSelector ID="Col1_StartTime1" runat="server" DisplaySeconds="False" ReadOnly="true" MinuteIncrement="1" AmPm="AM" BorderColor="Silver" 
                            Date="" Hour="07" Minute="0"  SelectedTimeFormat="Twelve"></MKB:TimeSelector>
<MKB:TimeSelector ID="Col1_EndTime1" runat="server" DisplaySeconds="False"  ReadOnly="true" MinuteIncrement="1" AmPm="PM" BorderColor="Silver" 
                            Date="" Hour="07" Minute="0" SelectedTimeFormat="Twelve"></MKB:TimeSelector>

</ItemTemplate>
<EditItemTemplate>
<MKB:TimeSelector ID="Col1_StartTime1" runat="server" DisplaySeconds="False"  MinuteIncrement="1" AmPm="AM" BorderColor="Silver" 
                            Date="" Hour="07" Minute="0"  SelectedTimeFormat="Twelve"></MKB:TimeSelector>
<MKB:TimeSelector ID="Col1_EndTime1" runat="server" DisplaySeconds="False"  MinuteIncrement="1" AmPm="PM" BorderColor="Silver" 
                            Date="" Hour="07" Minute="0" SelectedTimeFormat="Twelve"></MKB:TimeSelector>
</EditItemTemplate> 

</asp:TemplateField>

<asp:TemplateField HeaderText="Leave/TOIL">
<ItemTemplate>
<asp:CheckBox
ID="cb1_VL" Enabled="false" Text="VL" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_VL")%> />
<asp:CheckBox
ID="cb1_SL" Enabled="false" Text="SL" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_SL")%> />
<asp:CheckBox
ID="cb1_ML" Enabled="false" Text="ML" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_ML")%> />
<asp:CheckBox
ID="cb1_PH" Enabled="false" Text="PH" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_PH")%> />
<asp:CheckBox
ID="cb1_APH" Enabled="false" Text="APH" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_APH")%> />
<asp:CheckBox
ID="cb1_TOIL" Enabled="false" Text="TOIL" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_TOIL")%> />
<br />
<%#DataBinder.Eval(Container.DataItem, "Col1_Others")%>
</ItemTemplate>
<EditItemTemplate>

<asp:CheckBox
ID="cb1_VL" Text="VL" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_VL")%> />
<asp:CheckBox
ID="cb1_SL"  Text="SL" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_SL")%> />
<asp:CheckBox
ID="cb1_ML"  Text="ML" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_ML")%> />
<asp:CheckBox
ID="cb1_PH"  Text="PH" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_PH")%> />
<asp:CheckBox
ID="cb1_APH"  Text="APH" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_APH")%> />
<asp:CheckBox
ID="cb1_TOIL" Text="TOIL" 
runat="server"
Checked=<%#DataBinder.Eval(Container.DataItem, "Col1_TOIL")%> />
<asp:TextBox ID="tb1_Others" runat="server" Width="50" Text='<%#DataBinder.Eval(Container.DataItem, "Col1_Others") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

…………

</Columns>
</asp:GridView>    
</asp:Content>

Joe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:45:37+00:00Added an answer on May 23, 2026 at 8:45 am

    In those events you need to say: (e.g. to find text box named txtName)

    var txtName = e.Row.FindControl("txtName") as TextBox;
    

    (look at the ASPX markup code to see what’s the name of your input element name – give it one if it doesn’t have)
    then use the code above to read your element in your grid view event handler. (Cast it to the write input control type – i.e. TextBox, CheckBox, etc.)

    This is valid in most of grid view events,
    Also in list view you can say:

    var txtName = e.Item.FindControl("txtName") as TextBox;
    

    In some events, you have the row as a part of “e” (e.g. RowCreated, RowDataBound). In some other (like RowUpdated) you have e.RowIndex, which you can use to say

    grid.Rows[e.RowIndex].FindControl<...
    

    you can even go through all your rows and find your controls, in rows that are being editted

    foreach (GridViewRow row in gridList.Rows)
    {
        if (row.RowState == DataControlRowState.Edit)
        {
            var txtName = row.FindControl("txtName") as TextBox;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my asp.net + VB Gridview, I had bind several column from datatable into
I have an ASP .NET GridView with Paging. One column in it has a
I have a ASP.NET/VB that had a GridView to display a list of users
I have a ASP.NET GridView with a column mapped to a boolean. I want
I have ASP.NET GridView in my web app and would like to bind two
I have an ASP.NET gridview component which is being filled up with data from
I have a standard ASP.NET GridView and I'd like the first column (a emplateField
I have an ASP.Net GridView, with two columns (ID and name). The name column
I have a ASP.net gridview that I am trying bind to. My DataSource has
I have an ASP.NET GridView which has columns that look like this: | Foo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.