|
I've decided to change this to VB.Net. No one seems to be able to figure out exactly what's wrong with my C# Code.
I'm still having some problems. But I think it will be much easier to solve in VB.Net. I'm currently getting the error message: Compiler Error Message: BC30367: Class 'System.Web.UI.WebControls.DataGrid' cannot be indexed because it has no default property.
Source Error:
|
Line 52:
Line 53:
Line 54: MonthName = dtrPayment("Month_Year").ToString
|
Here's my VB.Net code:
<%@ Import Namespace="System.Data.SqlClient" %> <%@ Page Language="VB" Debug="true" %> <Script Runat="Server">
Dim strConnect As String Dim conPayment As SqlConnection Dim cmdSql As SqlCommand Dim strSql As String Dim strMonthID As String Dim MonthName As String
Sub Page_Load 'Get connection string from Web.Config strConnect = ConfigurationSettings.AppSettings("ConnectionString") conPayment = New SQLConnection(strConnect) If Not IsPostBack Then BindDataGrid End If End Sub
Sub BindDataGrid
'Get incoming Month ID strMonthID = request.params("ID")
'Start Sql statement strSql = "Select * From MonthInfo, Amounts, Clients" strSql = strSql & " where MonthInfo.MonthID = Amounts.MonthID" strSql = strSql & " and Amounts.ClientID = Clients.ClientID" strSql = strSql & " and UserName = '" & Session("UserName") & "'" strSql = strSql & " and MonthInfo.MonthID = '" & strMonthID & "'" strSql = strSql & " Order By AmountID" &nbs p; cmdSql = new SqlCommand(strSql, conPayment) conPayment.Open()
'if(dtrPayment.HasRows) - Needs Help With Changing This. I would like to find out if a record exists or not.
'dtrPayment.Visible = true dtrPayment.DataSource = cmdSql.ExecuteReader() dtrPayment.DataBind()
MonthName = dtrPayment("Month_Year").ToString -The error message 'Display Month Name 'lblMonthName.Text = "Payments For " & MonthName
'else 'dtrPayment.Visible = false
'don't forget to close the reader !!! 'dtrPayment.Close() conPayment.Close()
'end if
End Sub
</Script>
<html> <head><title>Amounts</title></head> <body>
<h1><asp:Label id="lblMonthName" runat="server"/> </h1> <form Runat="Server">
<asp:DataGrid ID="dtrPayment" DataKeyField="AmountID" AutoGenerateColumns="False" CellPadding="10" HeaderStyle-BackColor="tan" Runat="Server"> <Columns>
<asp:BoundColumn HeaderText="Service" DataField="Service" />
<asp:BoundColumn HeaderText="Payment Method" DataField="PaymentMethod" /> <asp:BoundColumn HeaderText="Payment Owed" DataField="PaymentOwed" DataFormatString="{0:C}"/> <asp:BoundColumn HeaderText="Paid Date" DataField="PaidDate" DataFormatString="{0:MM/dd/yyyy}"/>
</Columns> </asp:DataGrid>
</form> </body> </html>
|