Get a DropDownList item from a Gridview - asp.net

I'm using Visual Basic with ASP.NET. I have a GridView table with a DroDownList column and I need a way to get the selected item from it. Now I'm using an ImageButton in order to get the selected item from the DropDownList to pop-up as a message box. I already know how to get an integer from a boundfield. However, using the same code to get the DropDownList item won't work.
This is a snippet from my code:
ASP code:
<asp:BoundField DataField="Case#" HeaderText="Case#" ReadOnly="True" />
<asp:TemplateField HeaderText="Surgery Time">
<ItemTemplate>
<asp:DropDownList ID="Time_Slot" runat ="server">
<asp:ListItem Selected="True" Value="0">Select...</asp:ListItem>
<asp:ListItem Value="1">8:00</asp:ListItem>
<asp:ListItem Value="2">9:00</asp:ListItem>
<asp:ListItem Value="3">10:00</asp:ListItem>
<asp:ListItem Value="4">11:00</asp:ListItem>
<asp:ListItem Value="5">12:00</asp:ListItem>
<asp:ListItem Value="6">1:00</asp:ListItem>
<asp:ListItem Value="7">2:00</asp:ListItem>
<asp:ListItem Value="8">3:00</asp:ListItem>
<asp:ListItem Value="9">4:00</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField buttontype="Image" ImageUrl="~/Images/check.jpg" commandname="Accept" HeaderText="Accept" SortExpression="Accept" />
Visual Basic code:
Sub GridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Accept" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim selectedRow As GridViewRow = GridView1.Rows(index)
'This value is retrieved from the databound
Dim contactCell As TableCell = selectedRow.Cells(0)
Dim contact As String = contactCell.Text
'however here it is not retrieved from the dropdownlist
Dim contactCell2 As TableCell = selectedRow.Cells(1)
Dim contact2 As String = contactCell2.Text
MsgBox("case number is" + contact + "time is" + contact2)
End If
End Sub

Try this.
If e.CommandName = "Accept" Then
Dim index = e.CommandArgument
Dim timeSlot = CType(gridview1.Rows(index).FindControl("Time_Slot"), DropDownList)
Dim selectedTimeSlot = timeSlot.SelectedValue
End If

Related

how to get all values of selected checkbox in vb.net and set it on string list

I need to get selected items on checkbox and set as string format like (value1,value2,value3) from the checkbox i selected
For Each row As GridViewRow In GridView1.Rows
If row.RowType = DataControlRowType.DataRow Then
Dim CheckRow As CheckBox = (TryCast(row.Cells(1).FindControl("chckSelector"), CheckBox))
If CheckRow.Checked Then
Dim scode As String = TryCast(row.Cells(2).FindControl("lblsstorecode"), Label).Text
lbltest.Text = 'this i want to get the value like this (value1,value2,value3) from checkbox that i selected
End If
End If
Next
Depending on why you are using the GridView control, you might me able to accomplish this easier by using a CheckBoxList instead. In Asp.net what you describe is accomplished very easily with a CheckBoxList as follows:
In .aspx:
<asp:CheckBoxList ID="Itemlst" runat="server" RepeatColumns="1">
<asp:ListItem Value="">Item 1</asp:ListItem>
<asp:ListItem Value="">Item 2</asp:ListItem>
<asp:ListItem Value="">Item 3</asp:ListItem>
</asp:CheckBoxList>
</br>
<asp:Button ID="Button1" runat="server" Text="Button" />
</br>
<asp:TextBox ID="TextBox1" runat="server" Width="400"></asp:TextBox>
Then in the code behind:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim selected = New List(Of ListItem)
Dim itemcount As Integer
Dim csvlist As String = ""
For Each item As ListItem In Itemlst.Items
If item.Selected Then selected.Add(item)
Next
itemcount = selected.Count
For i = 0 To itemcount - 1
csvlist = csvlist & selected(i).ToString & ","
Next
csvlist = Mid(csvlist, 1, Len(csvlist) - 1)
TextBox1.Text = csvlist
End Sub
The Windows Forms CheckedListBox would probably work similar if you are developing a desktop application.

copy row from asp.net gridview to new page using VB

I am trying to copy a row from a gridview to be displayed on a new page through a button in one of the columns in the gridview. I have my gridview populated from an Access database that is linked to my project. I have tried several different things, but nothing will display the row information when the project is ran. The current code I am trying from the actual dataview is:
Example 1a
<asp:GridView ID="Grid1" runat="server" Width ="90%" AutoGenerateColumns="false" OnRowDeleting="Grid1_RowDeleting" DataKeyNames="Title">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Console" HeaderText="Console" />
<asp:BoundField DataField="Year_Released" HeaderText="Year Released" />
<asp:BoundField DataField="ESRB" HeaderText="ESRB Rating" />
<asp:BoundField DataField="Score" HeaderText="Personal Score" />
<asp:BoundField DataField="Publisher" HeaderText="Publisher" />
<asp:BoundField DataField="Developer" HeaderText="Developer" />
<asp:BoundField DataField="Genre" HeaderText="Genre" />
<asp:BoundField DataField="Purchase" HeaderText="Purchase Date" />
<asp:TemplateField ItemStyle-Width="7%" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnkDetails" runat="server" Text="View" PostBackUrl='<%# "~/ViewDetails.aspx?RowIndex=" & Container.DataItemIndex %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the codebehind code on the page where I am trying to have the code be displayed is:
Example 1b
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Me.Page.PreviousPage IsNot Nothing Then
Dim rowIndex As Integer = Integer.Parse(Request.QueryString("RowIndex"))
Dim GridView1 As GridView = DirectCast(Me.Page.PreviousPage.FindControl("Grid1"), GridView)
Dim row As GridViewRow = GridView1.Rows(rowIndex)
lblTitle.Text = row.Cells(0).Text
lblConsole.Text = row.Cells(1).Text
lblYear.Text = row.Cells(2).Text
lblESRB.Text = row.Cells(3).Text
lblScore.Text = row.Cells(4).Text
lblPublisher.Text = row.Cells(5).Text
lblDeveloper.Text = row.Cells(6).Text
lblGenre.Text = row.Cells(7).Text
lblPurchase.Text = row.Cells(8).Text
End If
End Sub
I have also tried another set of code where the button on the gridview was:
Example 2a
<asp:Button ID="btnLink" runat="server" Text="View Details" PostBackUrl='<%# Eval("Title", "~/ViewDetails.aspx?Id={0}") %>'/>
Where the codebehind code is:
Example 2b
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim GameTitle As String = Request.QueryString("Id")
Dim connString As String = "PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "DATA SOURCE=" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "App_Data" + "db1.accdb")
Using connection As New OleDbConnection(connString)
connection.Open()
Dim reader As OleDbDataReader = Nothing
Dim command As New OleDbCommand((Convert.ToString("SELECT * from [Video_Games] WHERE Title='") & GameTitle) + "'", connection)
reader = command.ExecuteReader()
While reader.Read()
lblTitle.Text = reader(0).ToString()
lblConsole.Text = reader(1).ToString()
lblYear.Text = reader(2).ToString()
lblESRB.Text = reader(3).ToString()
lblScore.Text = reader(4).ToString()
lblPublisher.Text = reader(5).ToString()
lblDeveloper.Text = reader(6).ToString()
lblGenre.Text = reader(7).ToString()
lblPurchase.Text = Convert.ToDateTime(reader(8).ToString()).ToShortDateString()
End While
End Using
End If
End Sub
End Class
I have tried making variations of both, mainly the second, but whatever I try the labels are not populated with the row information. Any assistance would be appreciated, and I can post any other code needed, like how I populated the gridview. Thank you.
It was as simple as changing the AutoEventWireup to "true" in my .aspx file.

GridView RowEditing event only fires on alternate rows

I have a GridView as below:
<asp:GridView ID="gvChain" runat="server" Font-Size="Small" CellPadding="3" CellSpacing="1" GridLines="None"
AutoGenerateColumns="False">
<HeaderStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Department" ControlStyle-Width="175px">
<EditItemTemplate>
<asp:Label ID="lblDepartment" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDepartment" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="175px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Manager Level 1" ControlStyle-Width="175px">
<ItemTemplate>
<asp:Label ID="lblManager1" runat="server" Text=""></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="cbManager1" runat="server"></asp:DropDownList>
</EditItemTemplate>
<ControlStyle Width="175px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Manager Level 2" ControlStyle-Width="175px">
<ItemTemplate>
<asp:Label ID="lblManager2" runat="server" Text=""></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="cbManager2" runat="server"></asp:DropDownList>
</EditItemTemplate>
<ControlStyle Width="175px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" CommandName="Edit" runat="server" Text="Edit" CssClass="buttonStyle" CausesValidation="false"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnSave" CommandName="Update" runat="server" Text="Save" CssClass="buttonStyle" CausesValidation="false"/>
<asp:LinkButton ID="btnCancel" CommandName="Cancel" runat="server" Text="Cancel" CssClass="buttonStyle" CausesValidation="false" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" CommandName="Delete" runat="server" Text="Delete" CssClass="buttonStyle" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The BoundField is populated in the Page_Load event as below:
Dim dHandler As DepartmentHandler = New DepartmentHandler
Dim depts As New List(Of Department)
depts = dHandler.GetDepartmentList
gvChain.DataSource = depts.
If Not Page.IsPostBack Then
gvChain.DataBind()
End If
Populating of the TemplateFields is then done in the RowDataBound event as below:
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Edit Then
Dim cbManager1 As DropDownList = TryCast(e.Row.FindControl("cbManager1"), DropDownList)
Dim cbManager2 As DropDownList = TryCast(e.Row.FindControl("cbManager2"), DropDownList)
Dim eHandler As EmployeeHandler = New EmployeeHandler
' Get the list of managers
Dim mgrs As New List(Of Manager)
mgrs = eHandler.GetManagerList
cbManager1.DataSource = mgrs
cbManager2.DataSource = mgrs
cbManager1.DataValueField = "Name"
cbManager1.DataTextField = "Name"
cbManager2.DataValueField = "Name"
cbManager2.DataValueField = "Name"
cbManager1.DataBind()
cbManager2.DataBind()
' Get the department name from the label in cell 0
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
' Pass the department name to the getManager1/2 functions to return the correct manager for that department
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
' Upper case the manager name to search the DDLs for item
Dim mgr1Name As String = mgr1.Name.ToUpper()
Dim mgr2Name As String = mgr2.Name.ToUpper()
' Find the manager in the DDL and select
cbManager1.SelectedValue = mgr1Name
cbManager2.SelectedValue = mgr2Name
Else
' If GV isnt in edit mode then populate labels in itemtemplate with manager 1 and 2 values
Dim lblManager1 As Label = DirectCast(e.Row.FindControl("lblManager1"), Label)
Dim lblManager2 As Label = DirectCast(e.Row.FindControl("lblManager2"), Label)
Dim eHandler As EmployeeHandler = New EmployeeHandler
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
lblManager1.Text = mgr1.Name
lblManager2.Text = mgr2.Name
End If
End If
I then have the below in the RowEditing event
gvChain.EditIndex = e.NewEditIndex
gvChain.DataBind()
When there is only 1 record displayed in the GridView, I click the edit button and the GridView goes into Edit mode I am able to update that record using the RowUpdating event and this works fine. However, if I add another record to the GridView, clicking on the edit button of that record gives a NullReference exception. If I then add another record, that 3rd record will go into edit mode. A 4th record will again fail with a NullReference exception and so on.
When debugging, it seems that on rows indexes 1,3,5 etc. the GridView doesn't go into edit mode however on row indexes 0, 2, 4 etc. the GridView will switch to edit mode.
This seems really strange behaviour. Any ideas what may be causing the GridView not to go into Edit mode on these rows?
A row's state can be one or a combination of the DataControlRowState values, so use bitwise operations to determine whether the state of the row includes a DataControlRowState value.
here
RowState contains more than one value (Alternate | Edit if you check RowState property during edit mode) using bit-logic.
Try
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
I got round this by amending the getDepartmentList function to return the Manager1 and Manager 2 fields then databinding them in the same was as I had bound 'Department'.
I then amended the RowDataBound event to the following:
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState And DataControlRowState.Edit Then
Dim cbManager1 As DropDownList = TryCast(e.Row.FindControl("cbManager1"), DropDownList)
Dim cbManager2 As DropDownList = TryCast(e.Row.FindControl("cbManager2"), DropDownList)
Dim eHandler As EmployeeHandler = New EmployeeHandler
' Get the list of managers
Dim mgrs As New List(Of Manager)
mgrs = eHandler.GetManagerList
cbManager1.DataSource = mgrs
cbManager2.DataSource = mgrs
cbManager1.DataValueField = "Name"
cbManager1.DataTextField = "Name"
cbManager2.DataValueField = "Name"
cbManager2.DataValueField = "Name"
cbManager1.DataBind()
cbManager2.DataBind()
' Get the department name from the label in cell 0
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
' Pass the department name to the getManager1/2 functions to return the correct manager for that department
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
' Upper case the manager name to search the DDLs for item
Dim mgr1Name As String = mgr1.Name.ToUpper()
Dim mgr2Name As String = mgr2.Name.ToUpper()
' Find the manager in the DDL and select
cbManager1.SelectedValue = mgr1Name
cbManager2.SelectedValue = mgr2Name
End If
End If

find radiobuttonlist in gridview

How can I find radiobuttonlist and it's items in gridview?
Gridview code:
<asp:TemplateField HeaderStyle-Width="20px">
<ItemTemplate>
<asp:RadioButtonList ID="rbl_NIU" runat="server" RepeatDirection="Horizontal" BorderStyle="None" BorderWidth="0px" BorderColor="Transparent">
<asp:ListItem Text="N" Value="1" ></asp:ListItem>
<asp:ListItem Text="I" Value="2" ></asp:ListItem>
<asp:ListItem Text="U" Value="3" ></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
and .vb code:
Protected Sub gvImport_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvImport.RowDataBound
'Dim radio As RadioButtonList = DirectCast(e.Row.FindControl("rbl_NIU"), RadioButtonList)
'Dim radio As RadioButtonList = TryCast(sender, RadioButtonList)
Dim radio As RadioButtonList = CType(e.Row.FindControl("rbl_NIU"), RadioButtonList)
For Each par As Paraugs In list
For Each item As RadioButton In radio.Items
par.Write.ToString()
Next
Next
End Sub
I have tried everything but every time I get "object reference not set to an instance of an object" in "For Each item" and On break-point "radio" returns "Nothing"
Where is the problem? Please help!
Thanks!
When you run the gvImport.RowDataBound this will still count headers, so you need a quick if statement at the top of the Sub:
If e.Row.RowType = DataControlRowType.DataRow Then
'Look for radio button list in this
End If

Why isn't the new values pulling up when I update the GridViewRow?

So what's happening is that I click the Edit button, type the updated values and hit Update. But the code-behind gets the original values not the updated values. I can't figure out why. It's always worked before.
Markup
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
CellPadding="7" ForeColor="#333333" GridLines="None" Font-Size="Small"
ShowFooter="True" DataKeyNames="CapID">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="AllocationId">
<ItemTemplate>
<asp:Label ID="show" runat="server" Text='<%# Eval("CapID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reference Number">
<ItemTemplate>
<asp:Label ID="showRefNo" runat="server" Text='<%# Eval("RefNo") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="EditRefNo"
Text='<%# Bind("RefNo") %>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="InsertRefNo"
Text='<%# Bind("RefNo") %>'/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Resource">
<ItemTemplate>
<asp:Label ID="showResource" runat="server"
Text='<%# Eval("Resource") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="EditResource"
Text='<%# Bind("Resource") %>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="InsertResource"
Text='<%# Bind("Resource") %>'/>
</FooterTemplate>
</asp:TemplateField>
<!-- and so on... -->
</Columns>
<!-- styles etc -->
<EmptyDataTemplate>
Ref Num: <asp:TextBox ID="newRefNo" runat="server"/>
Resource: <asp:TextBox ID="newResource" runat="server"/>
Hours Allocated: <asp:TextBox ID="newHours" runat="server"/>
Week Offset: <asp:TextBox ID="newOffset" runat="server"/>
<asp:Button runat="server" ID="NewDataInsert"
CommandName="NewDataInsert" Text="Insert"/>
</EmptyDataTemplate>
</asp:GridView>
Code Behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not IsPostBack Then
GridView1_DataBind()
GridView2_DataBind()
End If
End Sub
Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As
GridViewUpdateEventArgs) Handles GridView2.RowUpdating
Dim capID As Label = GridView2.Rows(e.RowIndex).Cells(0)
.FindControl("show")
Dim refNo As TextBox = GridView2.Rows(e.RowIndex).Cells(1)
.FindControl("EditRefNo")
Dim resource As TextBox =
GridView2.Rows(e.RowIndex).Cells(2).FindControl("EditResource")
Dim hours As TextBox =
GridView2.Rows(e.RowIndex).Cells(3).FindControl("EditHours")
Dim offSet As TextBox =
GridView2.Rows(e.RowIndex).Cells(4).FindControl("EditOffset")
Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
Dim updateRows As DataRow() =
newResAlloc.Select("CapID = " & "'" & capID.Text & "'")
If (Not updateRows Is Nothing) And updateRows.Length > 0 Then
For Each updRow As DataRow In updateRows
updRow.BeginEdit()
updRow.Item("Refno") = refNo.Text
updRow.Item("Resource") = resource.Text
updRow.Item("Hours") = hours.Text
updRow.Item("Offset") = offSet.Text
updRow.EndEdit()
Next
End If
resourceInfo.updateResAllocations(newResAlloc)
GridView2.EditIndex = -1
GridView2_DataBind()
End Sub
This could be a million and one things. What have you checked? Have you narrowed it down?
Here's some starting points for you:
Put a breakpoint inside GridView2_RowUpdating to make sure it's being called.
Check the value of capID, or capID.Text - it shouldn't be 0.
Check that your database table contains a row where CapID equals the value of capID.Text
Put a breakpoint on updateRows to ensure that the database row is being loaded into your code.
Make sure that the updRow.EndEdit() is being hit, and that the values are populated into the row correctly.
Finally, check that the updateResAllocations is working properly. It's impossible to see from here how it works, so I can't give any advice on that.
The easiest way to fix this might be to ask whoever wrote it for some assistance.
The problem was that my RowCommand method was calling the DataBind
Wrong way:
Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView2.RowCommand
If e.CommandName = "NewDataInsert" Then
Dim refNo As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewRefNo")
Dim resource As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewResource")
Dim hours As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewHours")
Dim offset As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewOffset")
Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
Dim newAllocRow As DataRow = newResAlloc.NewRow
newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
newResAlloc.Rows.Add(newAllocRow)
resourceInfo.updateResAllocations(newResAlloc)
ElseIf e.CommandName = "InsertNew" Then
Dim refNo As TextBox = GridView2.FooterRow.FindControl("InsertRefNo")
Dim resource As TextBox = GridView2.FooterRow.FindControl("InsertResource")
Dim hours As TextBox = GridView2.FooterRow.FindControl("InsertHours")
Dim offset As TextBox = GridView2.FooterRow.FindControl("InsertOffset")
Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
Dim newAllocRow As DataRow = newResAlloc.NewRow
newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
newResAlloc.Rows.Add(newAllocRow)
resourceInfo.updateResAllocations(newResAlloc)
End If
GridView2_DataBind() 'Culprit
End Sub
Right way:
Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView2.RowCommand
If e.CommandName = "NewDataInsert" Then
Dim refNo As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewRefNo")
Dim resource As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewResource")
Dim hours As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewHours")
Dim offset As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewOffset")
Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
Dim newAllocRow As DataRow = newResAlloc.NewRow
newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
newResAlloc.Rows.Add(newAllocRow)
resourceInfo.updateResAllocations(newResAlloc)
GridView2_DataBind() 'Only called if IF is true
ElseIf e.CommandName = "InsertNew" Then
Dim refNo As TextBox = GridView2.FooterRow.FindControl("InsertRefNo")
Dim resource As TextBox = GridView2.FooterRow.FindControl("InsertResource")
Dim hours As TextBox = GridView2.FooterRow.FindControl("InsertHours")
Dim offset As TextBox = GridView2.FooterRow.FindControl("InsertOffset")
Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
Dim newAllocRow As DataRow = newResAlloc.NewRow
newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
newResAlloc.Rows.Add(newAllocRow)
resourceInfo.updateResAllocations(newResAlloc)
GridView2_DataBind() 'Only called if IF is true
End If
End Sub

Resources