Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Heading Above The DataGrid
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Heading Above The DataGrid

 Post Reply Post Reply Page  <12
Author
Leeb65 View Drop Down
Groupie
Groupie


Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Leeb65 Quote  Post ReplyReply Direct Link To This Post Posted: 10 August 2005 at 3:00am

MonthName = reader["Month_Year"].ToString();

use that instead, that's C# the other is VB
Lee


Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 10 August 2005 at 5:12am
That code is in C# though, so the as keyword is fine. Unless you've never met as before, it's kinda like using

(string) statement;

But it only works for reference types and is equivalent to:

statement == null ? null : (type) statement;
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 11 August 2005 at 2:21am
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>
 
 
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.