[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

asp.net

i want to create a method from the code-behind that will bind fetched data from the database to the datagrid on the layout page.:
i have the error:
Error      1      Ambiguity between 'ShowRejected.whoRejected.GridView1' and 'ShowRejected.whoRejected.GridView1'      E:\Users\eco\documents\visual studio 2010\Projects\ShowRejected\ShowRejected\whoRejected.aspx.cs      43      13      ShowRejected.
Question: what is the cause of this error.
Question: How can i achieve my goal.
pls advice.

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.Configuration;



namespace ShowRejected
{
    public partial class whoRejected : System.Web.UI.Page
    {

        public RadioButton RadioButton1;
        public RadioButton RadioButton2;
        public RadioButton RadioButton3;
        public RadioButton RadioButton4;
        public RadioButton RadioButton5;
        public RadioButton RadioButton6;
        public GridView GridView1;
        string sqlQuery;




        protected void Page_Load(object sender, EventArgs e)
        {

        }
         String showrejectatBK01(string stationid)
        {
   
            SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IDKitConnectionString_test_ec"].ToString());
            SqlCommand mycommand = new SqlCommand("SELECT NIN,Nationality,gender,ApprovalStatus,ReceiptNo From Bio_data where DAY(DateCreated)=DAY(GETDATE() AND MONTH(DateCreated=MONTH(GETMONTH()AND YEAR(DateCreated=YEAR(GETYEAR()) AND  ApprovalStatus= 'Rejected' AND ReceiptNo like'ytr%'", dbconnection);

            SqlDataReader Retrieve_data;
            dbconnection.Open();
            Retrieve_data = mycommand.ExecuteReader();

            GridView1.DataSource = Retrieve_data;
            GridView1.DataBind();
                    

        }

    }
}

Open in new window

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="whoRejected.aspx.cs" Inherits="ShowRejected.whoRejected" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Overview of Rejected Applicants</title>
    <script type = "text/css">
          p {border-style:double; border-width:thick;border-color: ActiveBorder;}
          img1{float:left}
          img1{float:left}
          p {text-align:center; font-size:24pt;color:white;background-color:Maroon;
            width: 1020px;
            margin-left: 4px;}
        
        </script> 
           

</head>
<body>
    <form id="form1" runat="server">
    
     <div>
    
              <table>
                    <tr><td valign= "top"><img src = "statistics.gif"  style= "width:200px; height:100px"/></td></tr>
                            
               </table>        
            
             <center> <p> STATISTIC  PER STATION:</p></center>
            
         </div>  

         <div style="width: 775px">  
  
       
       <br />
      <asp:RadioButton ID="RadioButton1" runat="server" GroupName = "StationID" Text= "BK01" Checked ="true"  ForeColor= "black"/>  
      
      <br />  
      <asp:RadioButton ID="RadioButton2" runat="server" GroupName = "StaionID" Text = "BJL01" ForeColor = "black"/>  
      <br />
      <asp:RadioButton ID="RadioButton3" runat="server" GroupName = "StationID" Text = "BS01" ForeColor = "black"/>
      <br />
      <asp:RadioButton ID="RadioButton4" runat="server" GroupName = "StationID" Text = "FF01" ForeColor = "black"/>
      <br />
      <asp:RadioButton ID="RadioButton5" runat="server" GroupName = "StationID" Text = "SK01" ForeColor = "black"/>
      <br />
     <h1>

                <asp:GridView ID="GridView1" runat="server" Width="774px">
                </asp:GridView>


</h1>
            </div> 
    
    </form>
</body>
</html>

Open in new window

0
Atouray
Asked:
Atouray
  • 3
  • 2
4 Solutions
 
dexterrajeshCommented:
hi,

you have a public field of type declared

public GridView GridView1;

and a control in the designer which causes the error

<asp:GridView ID="GridView1" runat="server" Width="774px">
                </asp:GridView>

remove the code public GridView GridView1; at line 23 if you have not used it else rename it to other name...
0
 
Ajay SharmaCommented:
On line number 23 and 51 you have declared the gridview with same ID, please change the name/ID of any of them to a different one. e.g. set the ID="GridView2" on line 51
0
 
dexterrajeshCommented:
also, why these declarations when you have them created in your designer  code ?

public RadioButton RadioButton1;
public RadioButton RadioButton2;
public RadioButton RadioButton3;
public RadioButton RadioButton4;
public RadioButton RadioButton5;
public RadioButton RadioButton6;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AtourayAuthor Commented:
i declare the radiobuttons in the code-behind file,
because i want to read data from my database base on the radionbutton selected on the layout
0
 
dexterrajeshCommented:
the controls in ur layout are server controls which you can refer straight away in the code behind
0
 
AtourayAuthor Commented:
thank.
that was fine.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now