How to set a nested datasource from code behind? - asp.net

Connection String (Conn) is set globally on page load.
(As below. I use this for all sqldatasources and it work perfectly.)
VB.NET (Page Load)
Imports Connections
Dim Conn As New System.Data.SqlClient.SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Conn.ConnectionString = ConfigurationManager.ConnectionStrings(StringConn).ConnectionString
sqlRepeater.ConnectionString = Conn.ConnectionString
End Sub
How to set a nested datasource from code behind?
I have a nested gridview inside a repeater and am trying to set the sqldatasource's connectionstring on itemdatabound instead of page load. (As below.)
VB.NET (Repeater Item Databound)
Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rpt.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim sqlGridview As SqlDataSource = DirectCast(e.Item.FindControl("sqlGridview"), SqlDataSource)
sqlGridview.ConnectionString = Conn.ConnectionString
End If
End Sub
ASPX
<asp:Repeater ID="rpt" runat="Server" DataSourceID="sqlRepeater">
<ItemTemplate>
<asp:GridView ID="gv" runat="Server" AutoGenerateColumns="False" DataSourceID="sqlGridview">
...
</GridView>
<asp:SqlDataSource ID="sqlGridview" runat="Server" SelectCommand="sp" SelectCommandType="StoredProcedure"/>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sqlRepeater" runat="Server" SelectCommand="sp" SelectCommandType="StoredProcedure"/>
This code outputs error:
The ConnectionString property has not been initialized.
TRIED TO CREATE FUNCTION TO PASS IN THE CONNECTION STRING
ASPX
Replaceed above sqlsource with this to call function
<asp:SqlDataSource ID="sqlGridview" runat="Server" SelectCommand="sp" SelectCommandType="StoredProcedure" ConnectionString='<%# GetConnectionString()%>'/>
VB.NET
Protected Function GetConnectionString() As String
Dim Conn As New System.Data.SqlClient.SqlConnection
Conn.ConnectionString = ConfigurationManager.ConnectionStrings(StringConn).ConnectionString
Return Conn.ConnectionString
End Function

This is just an idea, but the problem might be the fact that by the time ItemDataBound is called GridView's data binding is already done, or was attempted to be done. And during this attempt a connection string was not set indeed.
To correct that you might want to do two things. First - set connection string in markup, so that data source has it before data binding is done. Something like this:
<asp:SqlDataSource ID="sqlGridview" runat="Server"
ConnectionString='<%# GetConnectionString(); %>' ... />
Where GetConnectionString is a protected method in code behind that just returns the
connection string:
Protected Function GetConnectionString() As String
Return Conn.ConnectionString
End Function
Of course that means that there is no need to handle ItemDataBound anymore, unless you were doing something else there as well.
Second - reverse the order of controls inside the item template. This most likely is not necessary, but I am not entirely sure about an exact time when the GridView will be data bound, so this will help to ascertain that connection string is set:
<ItemTemplate>
<asp:SqlDataSource ID="sqlGridview" runat="Server"
<asp:GridView ID="gv" runat="Server" ...
</ItemTemplate>

In Your Class Library
Use this to cast initially the sqlConnection then execute the connection when using it.
Public Class MyLibrary
'-------------------SQL Database Variables----------------
Dim SerialMACDatabase As String = Nothing
Dim SerialMac As SqlConnection
Dim CMD As New SqlCommand
Dim sqlAdapter As SqlDataAdapter
Public Sub New(ByVal lserialMACDatabase As String)
SerialMACDatabase = lserialMACDatabase
End Sub
Private Sub connectToDB()
Try
SerialMac = New SqlConnection(SerialMACDatabase)
SerialMac.Open()
Catch ex As Exception
End Try
End Sub
Public Sub issueCommand(ByVal sQuery As String)
Try
connectToDB()
CMD = New SqlCommand(sQuery, TestResult)
CMD.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Libraryy As New MyLibrary(strSQLCONNECTION)
Libraryy.IssueCommand("INSERT SOMETHING")
End Sub

Related

ASP.NET VB Dropdown List

ASP.NET dropdown populates correct items, but VB will not receive selected item. Not sure where to go from here. Could you please tell me why this is not occurring and how to resolve. I need to pass the selected item as a variable to the vb script.
ASP.NET:
<asp:DropDownList ID="ddlFacultyAssign" runat="server"
DataSourceID="FacultyAssign" Visible="false"
DataTextField="FULLNAME" DataValueField="FULLNAME"></asp:DropDownList>
<asp:SqlDataSource ID="FacultyAssign" runat="server"
ConnectionString="<%$ ConnectionStrings:nameOfString %>"
SelectCommand="EXEC SOCC.dbo.sp_util_FacultyAssign #PEOPLE_CODE_ID">
<SelectParameters>
<asp:QueryStringParameter Name="PEOPLE_CODE_ID" QueryStringField="USER" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
VB
Partial Public Class NotesContact
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.TextBox1.Text = Context.User.Identity.Name
Me.Calendar1.SelectedDate = DateTime.Today
If (Not IsPostBack) Then
ViewState("RefUrl") = Request.UrlReferrer.ToString()
End If
End Sub
Private Sub SAVE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SAVE.Click
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=**************************")
MyCommand = New SqlCommand("myStoredProcedure", MyConnection)
'Set the command type as StoredProcedure.
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Parameters.Add(New SqlParameter("#FACASSIGN", SqlDbType.VarChar, 200))
MyCommand.Parameters("#FACASSIGN").Value = Me.ddlFacultyAssign.SelectedItem.Text
'Open and execute the statement
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyConnection.Close() 'Close the connection
GridView1.DataBind()
I'm pretty sure you want to use
Me.ddlFacultyAssign.SelectedValue
Have you tried doing this?
MyCommand.Parameters("#FACASSIGN").Value =
Me.ddlFacultyAssign.Items.Item(Me.ddlFacultyAssign.SelectedIndex).Text.Trim
And have you considered putting your dropdownlist and gridview in an update panel?

GridView not populating on Page_Load but on PostBack or Refresh

In an ASP.NET WebForms application there are just two controls in an aspx page, a DropDownList and a GridView. There is no default selected value of DropDownList on Page_Load. Changing the selection in DropDownList populates GridView accurately.
When the page is requested with a URL parameter such as .../View_Details.aspx?C_ID=123, the selected value in DropDownList changes but GridView does not populate for the first time but refreshing the page shows the records for given URL parameter.
ASPX markup:
<%# Page Title="Data" Language="vb" AutoEventWireup="false" MasterPageFile="~/HomePage.Master" CodeBehind="View_Details.aspx.vb" Inherits="App1.View_Details" %>
<asp:Content ID="Content4" ContentPlaceHolderID="BodyCP" runat="server">
<asp:DropDownList ID="CIDCombo" runat="server" DataSourceID="SqlDSCID" DataTextField="CName" DataValueField="CID" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDSCID" runat="server" ... ></asp:SqlDataSource>
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Fld1" />
<asp:BoundField DataField="Fld2" />
...
</Columns>
</asp:GridView>
</asp:Content>
Code Behind:
Private C_ID As Long
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.Connect...)
Dim cmd As New SqlCommand()
Dim stSqlQry As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
C_ID = CLng(Request.QueryString("C_ID"))
If IsPostBack Then
Else
If C_ID > 0 Then
CIDCombo.SelectedValue = C_ID.ToString
LoadGVData(C_ID)
End If
End If
End Sub
Private Sub CIDCombo_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles CIDCombo.SelectedIndexChanged
If CIDCombo.SelectedIndex >= 0 AndAlso CLng(CIDCombo.SelectedValue) > 0 Then
LoadGVData(CLng(CIDCombo.SelectedValue))
End If
End Sub
Private Sub LoadGVData(ByVal lnCID As Long)
Try
If con.State <> ConnectionState.Open Then con.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter()
stSqlQry = "SELECT Fld1, Fld2 ... WHERE CID = #CID"
da = New SqlDataAdapter()
cmd = New SqlCommand(stSqlQry, con)
cmd.Parameters.AddWithValue("#CID", lnCID)
Dim dtDataTableInc As DataTable = New DataTable("t_Data")
da.SelectCommand = cmd
da.Fill(dtDataTableInc)
'SOME DATA MANIPULATION WITH DATATABLE'
'****************************************************************************'
'DEBUG MODE SHOWS DataTable HAS ROWS BUT DON'T SHOW UP FIRST TIME IN GRIDVIEW'
'****************************************************************************'
gvData.DataSource = dtDataTableInc
gvData.DataBind()
Catch ex As Exception
'EXCEPTION HANDLING
Finally
If con.State <> ConnectionState.Closed Then con.Close()
End Try
End Sub
I see you have AutoEventWireup="false" put it on true.
Just a general note:
When working with DropDownLists and using AutoPostBack=True
make use of an UpdatePanel since the User gets frustrated when he always see a white page flickering :)
if you use an UpdatePanel you use the Onload event to populate your data
and put UpdateMode=Conditional
Good luck and happy coding.

SelectedIndexChange event won't get fired,ASP.NET DropDownList

I have a Windows form with 1 DataGrid which has a Dropdownlist in one of its columns.
I also have another dropDownlist outside of this DataGrid.
Both of these dropdowns are bound to same dataset and both get populated with same items.
Both of DropDowns have their Autopostbacks set to true.
Problem is only for the dropdownlist Outside of Datagrid SelectedIndexChange Event gets fired:
(I have seen multiple similar questions on SO but none of suggestions works for me. So I really appreciate if you can help me here.
)
Protected Sub ABCD(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
For both Dropdownlists: AutoPostBack="True"
Here is Vb code:
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents dg As New System.Web.UI.WebControls.DataGrid
Private cnDB As New OleDbConnection
Private ds As New DataSet
Private daDB As New OleDbDataAdapter
Protected allNames As New DataSet
Protected MyDataSet As DataSet
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlName As New System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyDataSet = NameBudget()
GridDataLoad()
End Sub
Protected Sub Grid_EditCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
dg.EditItemIndex = e.Item.ItemIndex
dg.DataSource = ds
dg.DataBind()
End Sub
Protected Sub Grid_CancelCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
dg.DataSource = ds.Tables(0).DefaultView
dg.EditItemIndex = -1
dg.DataSource = ds
dg.DataBind()
End Sub
Protected Sub Grid_UpdateCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
End Sub
Private Function GridDataLoad()
ddlName.DataSource = MyDataSet
Dim i As Object = MyDataSet.Tables(0)
ddlName.DataBind()
DropDownList1.DataSource = MyDataSet
DropDownList1.DataBind()
Dim strCon As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessTestDataBases\TestDB.mdb; "
Dim cnDB As New OleDbConnection(strCon)
cnDB.Open()
daDB = New OleDbDataAdapter("Select * from [Persons]", cnDB)
daDB.Fill(ds, "tbl1")
Dim j As Object = ds.Tables(0)
dg.DataSource = ds
dg.DataBind()
cnDB.Close()
Dim ii As Object = ds.Tables(0)
End Function
Protected Function NameEditable(ByVal n As String) As Boolean
Return True
End Function
Protected Function NameBudget() As DataSet
Dim strCon As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessTestDataBases\TestDB.mdb; "
Dim cnDB As New OleDbConnection(strCon)
cnDB.Open()
daDB = New OleDbDataAdapter("Select ID,Name from [Persons]", cnDB)
Dim ds As New DataSet
daDB.Fill(ds, "tbl1")
cnDB.Close()
Return ds
End Function
Sub SetDefaultListItem(ByVal sender As Object, ByVal e As System.EventArgs)
'*************************************************************************
'* Use this sub to set the Default List for DropDown Listboxes *
'*************************************************************************
Try
If Len(sender.DefaultValue) > 0 Then
If sender.Items.FindByValue(sender.DefaultValue).ToString.Length > 0 Then
sender.Items.FindByValue(sender.DefaultValue).Selected = True
End If
End If
Catch ex As System.Exception
'Throw New System.Exception(ex.ToString())
End Try
End Sub
Protected Sub ABCD(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
Here is the HTML for datagrid and Dropdownlists:
<Columns>
<ASP:ButtonColumn Text="Delete" CommandName="Delete"></ASP:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<ASP:TemplateColumn HeaderText="Name" SortExpression="FY" HeaderStyle-HorizontalAlign="center" HeaderStyle-Wrap="True">
<ItemStyle Wrap="false" HorizontalAlign="left" />
<ItemTemplate>
<ASP:Label ID="Name" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' runat="server"/>
</ItemTemplate>
<EditItemTemplate>
<ASP:DropDownList id="DropDownlist2" datasource="<%# MyDataSet %>" DataTextField= "Name" DataValueField="ID" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ABCD">
</ASP:DropDownList>
</EditItemTemplate>
</ASP:TemplateColumn>
</Columns>
<asp:DropDownList id="DropDownList1"
datasource="<%# MyDataSet %>" DataTextField= "Name"
DataValueField="ID" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ABCD">
</asp:DropDownList>

Gridview updatepanel sorting Object reference not set to an instance of an object

I am attempting to sort a gridview in an updatepanel. It compiles, but I get an Object reverence not set to an instance of an object error. I am trying to follow this guide, but in vb
default.aspx
<ajx:UpdatePanel ID="ajaxpanel" runat="server">
<ContentTemplate>
<asp:GridView ID="gvProgramDetails" runat="server" AutoGenerateColumns="False"
CssClass="gridview" DataKeyNames="ProgramNumber"
AllowPaging="True" PageSize="2" AllowSorting="True" OnSorting="gvProgramDetails_Sorting">
<Columns>
<asp:CommandField ControlStyle-CssClass="button delete" ShowDeleteButton="True">
<ControlStyle CssClass="button delete" />
</asp:CommandField>
<asp:CommandField ControlStyle-CssClass="button save" ShowEditButton="True">
<ControlStyle CssClass="button save" />
</asp:CommandField>
<asp:BoundField DataField="ProgramNumber" HeaderText="ProgramNumber"
InsertVisible="False" ReadOnly="True" SortExpression="ProgramNumber" />
<asp:BoundField DataField="ProgramName" HeaderText="ProgramName"
SortExpression="ProgramName" />
<asp:BoundField DataField="ProgramStatus" HeaderText="ProgramStatus"
SortExpression="ProgramStatus" />
<asp:BoundField DataField="RecordType" HeaderText="RecordType"
SortExpression="RecordType" />
<asp:BoundField DataField="ProgramInformation" HeaderText="ProgramInformation"
SortExpression="ProgramInformation" />
</Columns>
</asp:GridView>
</ContentTemplate>
default.aspx.vb
Imports System.Web.Services
Partial Class processes_ProgramTrack_Default
Public Property SortOrder() As String
Get
If (ViewState("SortOrder").ToString = "desc") Then
ViewState("SortOrder") = "asc;"
Else
ViewState("SortOrder") = "desc"
End If
Return ViewState("SortOrder").ToString()
End Get
Set(ByVal value As String)
ViewState("SortOrder") = value
End Set
End Property
Public Sub bindGridView(Optional ByVal sortExp As String = "", Optional ByVal sortDir As String = "")
Dim connstr As String = ConfigurationManager.ConnectionStrings("WEBConnectionString").ConnectionString
Dim conn As New SqlConnection(connstr)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim myDataView As New DataView()
Dim mysqlCommand As New SqlCommand("SELECT tblPrgTrackPrograms.ProgramNumber, tblPrgTrackPrograms.ProgramName, tblPrgTrackPrograms.ProgramStatus, tblPrgTrackProgramDocumentation.RecordType, tblPrgTrackProgramDocumentation.ProgramInformation FROM tblPrgTrackPrograms INNER JOIN tblPrgTrackProgramDocumentation ON tblPrgTrackPrograms.ProgramNumber = tblPrgTrackProgramDocumentation.ProgramNumber")
Dim myDataSet As New DataSet()
Dim mySQLAdapter As New SqlDataAdapter(mysqlCommand)
mySQLAdapter.SelectCommand.Connection = conn
mySQLAdapter.Fill(myDataSet)
myDataView = myDataSet.Tables(0).DefaultView
If sortExp <> String.Empty Then
myDataView.Sort = String.Format("{0}{1}", sortExp, sortDir)
End If
gvProgramDetails.DataSource = myDataView
gvProgramDetails.DataBind()
End Sub
Protected Sub gvProgramDetails_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvProgramDetails.Load
bindGridView()
End Sub
Protected Sub gvProgramDetails_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvProgramDetails.PageIndexChanging
gvProgramDetails.PageIndex = e.NewPageIndex
bindGridView()
End Sub
Protected Sub gvProgramDetails_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvProgramDetails.RowDeleting
End Sub
Protected Sub gvProgramDetails_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvProgramDetails.Sorting
SortOrder = ViewState("SortOrder").ToString
bindGridView(e.SortExpression, SortOrder)
End Sub
End Class
I get the error message as a popup msgbox. What I think is happening, SortOrder isn't getting assigned a value.
You need to make sure that you ViewState("SortOrder") has a value in it before you try to call ToString. Otherwise, it will throw that exception (as you've seen) because you cannot call the ToString method on null.
Essentially, you need to wrap your references to that ViewState variable in a "If (ViewState("SortOrder") IsNot Nothing Then" block, and possibly provide special handling in the "Else" section (if you need that).
Something like this for your property:
Public Property SortOrder() As String
Get
If (ViewState("SortOrder") IsNot Nothing Then
If (ViewState("SortOrder").ToString = "desc") Then
ViewState("SortOrder") = "asc;"
Else
ViewState("SortOrder") = "desc"
End If
End If
Return ViewState("SortOrder").ToString()
End Get
Set(ByVal value As String)
ViewState("SortOrder") = value
End Set
End Property
And then the same thing for your sorting event:
Protected Sub gvProgramDetails_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvProgramDetails.Sorting
If (ViewState("SortOrder") IsNot Nothing Then
SortOrder = ViewState("SortOrder").ToString
bindGridView(e.SortExpression, SortOrder)
End If
End Sub
Note: This is my best guess at your problem, given the information you've provided so far. If you provide the line that's throwing the error, I'd be glad to take another look.

Repeater Button CommandArgument is Empty String

Losing my mind with this one. My button gets a commandargument of empty string even though the commandargument gets set. I have verified it gets set to the correct ID in debug mode, but then when I go to access this commandargument later in the repeaters ItemCommand event the commandarguments are empty string. And I have no idea why. I end up getting a sq foreign key exception because it is inserting an ID of 0 from the empty string values. There is no other code regarding the repeaters buttons that would be resetting it.
Repeater:
<asp:Repeater ID="repeaterAddresses" ViewStateMode="Enabled" DataSourceID="sqlFacilityAddresses" runat="server">
<ItemTemplate>
<Select:Address ID="AddressControl" runat="server" />
<asp:Button ID="btnMarkAsBilling" runat="server" EnableViewState="true" CommandName="Billing" Text="Mark as billing address" />
<asp:button ID="btnMarkAsPhysical" runat="server" EnableViewState="true" CommandName="Physical" Text="Mark as physical address" />
</ItemTemplate>
</asp:Repeater>
Code behind:
Protected Sub repeaterAddresses_ItemCreated(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles repeaterAddresses.ItemCreated
If Not IsNothing(DirectCast(e.Item.DataItem, DataRowView)) Then
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim addressControl As Address = DirectCast(e.Item.FindControl("AddressControl"), Address)
addressControl.AddressID = CInt(DirectCast(e.Item.DataItem, DataRowView)("Address_ID").ToString())
Dim btnBilling As Button = DirectCast(e.Item.FindControl("btnMarkAsBilling"), Button)
btnBilling.CommandArgument = CInt(DirectCast(e.Item.DataItem, DataRowView)("Address_ID").ToString())
Dim btnPhysical As Button = DirectCast(e.Item.FindControl("btnMarkAsPhysical"), Button)
btnPhysical.CommandArgument = CInt(DirectCast(e.Item.DataItem, DataRowView)("Address_ID").ToString())
End If
End If
End Sub
Protected Sub repeaterAddress_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles repeaterAddresses.ItemCommand
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Trustaff_ESig2").ConnectionString)
Dim button As Button = CType(e.CommandSource, Button)
Select Case e.CommandName
Case "Billing"
Dim cmdBillingAddress As New SqlCommand("[SP_Facility_UpdateBillingAddress]", conn)
With cmdBillingAddress
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("#Facility_ID", DbType.Int32)).Value = sqlFacilityAddresses.SelectParameters("Facility_ID").DefaultValue
.Parameters.Add(New SqlParameter("#BillingAddress_ID", DbType.Int32)).Value = e.CommandArgument
End With
conn.Open()
cmdBillingAddress.ExecuteNonQuery()
conn.Close()
Case "Physical"
Dim cmdPhysicalAddress As New SqlCommand("[SP_Facility_UpdatePhysicalAddress]", conn)
With cmdPhysicalAddress
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("#Facility_ID", DbType.Int32)).Value = sqlFacilityAddresses.SelectParameters("Facility_ID").DefaultValue
.Parameters.Add(New SqlParameter("#PhysicalAddress_ID", DbType.Int32)).Value = e.CommandArgument
End With
conn.Open()
cmdPhysicalAddress.ExecuteNonQuery()
conn.Close()
End Select
PopulateBillingPhysicalAddresses(sqlFacilityAddresses.SelectParameters("Facility_ID").DefaultValue)
End Sub
Try this:
<asp:Button ID="btnMarkAsBilling" runat="server" EnableViewState="true"
CommandName="Billing" Text="Mark as billing address"
CommandArgument='<%# Eval("Address_ID") %>'/>
Note the single quotes around the attribute value. ASP.NET will not execute the server side data binding code if they are double quotes. You'll need to remove the CommandArgument assignments from your code behind.
Address_ID will need to be a property on the object you are databinding to the repeater.

Resources