I have 2 error messages with my c# webform, that i can not handle by myself.
Add.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Add.aspx.cs" Inherits="keszlet_management.Add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<p>
<br />
</p>
<p>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</p>
</asp:Content>
Add.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
public object GridView1 { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM items"))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
}
I am new in C#, so I know i have several mistakes, please focus on error messages:
1.: Severity Code Description Project File Line Suppression State
Error CS1061 'object' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
2.: The same message with 'DataBind'
GridView1as typeobjectandobjectdoes not have those methods/properties. Perhaps you should define it asGridViewor try doing a cast. - Chris Dunaway