?
Solved

How bind a datarid to a void method

Posted on 2011-10-19
4
Medium Priority
?
291 Views
Last Modified: 2013-12-16
I Create a method of type:void that read data from my database.
i want to bind this method to the gridview control on the layout file.
how can i achieve this.
pls check both Codebehind and the lay out files.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;

namespace GambiaStat
{
    public partial class Showrejected : System.Web.UI.Page
    {
        public RadioButton RadioButton1;
        public RadioButton RadioButton2;
        public RadioButton RadioButton3;
        public RadioButton RadioButton4;
        public RadioButton RadioButton5;
        public RadioButton RadioButton6;
        public Calendar canlenderone, calendertwo;
        public GridView showgrid;
        

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        void selectedDate()
        {
            if (RadioButton1.Checked)
            {
              

            }


        }

        void ShowrejectAtBK01()
        {

            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'450%'", dbconnection);

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

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


        }

Open in new window

aspx:page
       <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>

Open in new window

0
Comment
Question by:Atouray
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36992296
You can not bind it on aspx page.
You have to call you function on page load Event as below.

protected void Page_Load(object sender, EventArgs e)
{
        if(!isPostBack)
        {
              ShowrejectAtBK01();
           }
  }

0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 1600 total points
ID: 36992317
Your Code will be

 <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="showgrid" runat="server" Width="774px">
                </asp:GridView>


</h1>

 public partial class Showrejected : System.Web.UI.Page
    {                

        protected void Page_Load(object sender, EventArgs e)
        {
                   if(!isPostBack)
                   {
                           ShowrejectAtBK01();
                       }

        }

        void selectedDate()
        {
            if (RadioButton1.Checked)
            {
             

            }


        }

        void ShowrejectAtBK01()
        {

            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'450%'", dbconnection);

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

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


        }
0
 
LVL 4

Assisted Solution

by:guramrit
guramrit earned 400 total points
ID: 36992384
modify your page_load in code behind to :-

protected void Page_Load(object sender, EventArgs e)
{
        if(!isPostBack)
        {
              ShowrejectAtBK01();
           }
  }

 
0
 

Author Closing Comment

by:Atouray
ID: 36993237
Thank you..
precise, clear and correct answer.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question