Click here to Skip to main content
14,360,161 members
Rate this:
Please Sign up or sign in to vote.
See more:
Gridview Not Showing.


1. Data is coming fro 2 DATABASES WHR & WPAY

protected void Page_Load(object sender, EventArgs e)
{

///Load Begin
if (!IsPostBack)
{
try
{

txt_Run_Date.Text = DateTime.Now.Date.ToString("dd MMM yyyy");


SqlConnection connect = new SqlConnection();
connect.ConnectionString = ConfigurationManager.ConnectionStrings["WEBPAY"].ConnectionString;
connect.Open();

SqlDataAdapter da = new SqlDataAdapter("select * FROM pycntrun where runyear*100000+runmonth=(select max(runyear*100000+runmonth) from pycntrun)", connect);

DataSet ds = new DataSet();
da.Fill(ds, "PYCN");

txt_Period.Text = ds.Tables["PYCN"].Rows[0]["RUNMONTH"].ToString();
txt_Year.Text = ds.Tables["PYCN"].Rows[0]["RUNYEAR"].ToString();

lblReport.Text = ds.Tables["PYCN"].Rows[0]["LOANRUN"].ToString();


if (lblReport.Text == "YES")
{
lblReport.Text = "Loan Processing For This Month Done";
// btn_Process.Enabled = false;
}
else
{
lblReport.Text = "Loan Processing Yet To Be Run";
}

connect.Close();


GridView1.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);


SqlConnection ccc = new SqlConnection();
connect.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
connect.Open();


SqlDataAdapter daas = new SqlDataAdapter(@"Select IDNO,EMPNO,FNAME,LNAME,DEPTNAME from WHR.dbo.PAYMAST
where WHR.dbo.PAYMAST.IDNO not in
(select idno from WPAY.dbo.Paycurrt)", ccc);


DataSet dsas = new DataSet();
daas.Fill(dsas, "Paycurrt");
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();

lblstatus.Text = "Record Load successful";
connect.Close();

GridView1.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);


}
catch (Exception ex)
{
lblstatus.Text = ex.Message;
}

}


How do I get the GRIDVIEW to Load ?

Thanks

What I have tried:

Oongoing developmental Challenge requires help
Posted
Updated 8-Nov-19 10:19am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

GridView1.DataSourceID = "SqlDataSource1";

I cannot see a definition of "SqlDataSource1" anywhere in the above code. What is it supposed to refer to? And there does not seem to be any reference between your data grid and the data sets that you created.
   
v2
Comments
Member 12770648 6-Nov-19 12:36pm
   
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//GRIDVIEW BEGIN

//txtSave.Enabled = false;
try
{
//connection to the database
//
//
string str;
str = ConfigurationManager.ConnectionStrings["WEBPAY"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(str);

string intno;

//Get the intno
intno = GridView1.SelectedRow.Cells[1].Text;

//call the stored procedure
SqlCommand SqlCmd = new SqlCommand("sp_pers_trans", sqlcon);
SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;


//Supply the User_id parameter
// SqlCmd.Parameters.AddWithValue("@BRNNO", intno);

//Create and supply the output parameters

// SqlCmd.Parameters.Add("@BRETURN", System.Data.SqlDbType.VarChar, 12);
// SqlCmd.Parameters["@BRETURN"].Direction = System.Data.ParameterDirection.Output;

//Open the sql data connection
sqlcon.Open();

//Execute the stored procedures
SqlCmd.ExecuteNonQuery();

//Assign the results to the controls


lblstatus.Text = "Grid record successful";

//
//
sqlcon.Close();
}
catch (Exception ex)
{
lblstatus.Text = ex.Message;

}

//GRIDVIEW END
}
Richard MacCutchan 6-Nov-19 12:46pm
   
How does that fit with the code in your question? And I still cannot see any connection between the GridView and the results of your SQL queries.
Member 12770648 7-Nov-19 7:14am
   
USE [WPAY]
GO
/****** Object: StoredProcedure [dbo].[sp_pers_trans] Script Date: 11/03/2019 19:27:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[sp_pers_trans]
(
@BRETURN varchar(20) output
)

AS
Begin
Begin


CREATE TABLE #SearchResults
(
Zidno varchar(50),
Zempno varchar(80),
Zfname varchar(50),
Zlname varchar (50),
Zdeptname varchar (50)
)

Insert Into #SearchResults(Zidno,Zempno,Zfname,Zlname,Zdeptname)
Select IDNO,EMPNO,FNAME,LNAME,DEPTNAME from WHR.dbo.PAYMAST where WHR.dbo.PAYMAST.IDNO not in
(select idno from WPAY.dbo.Paycurrt);



IF EXISTS (SELECT * FROM #SearchResults)
BEGIN
Select Zidno 'IDNO' ,
Zempno 'EMPNO',
Zfname 'FNAME',
Zlname 'LNAME',
Zdeptname 'DEPTNAME'
From #SearchResults ORDER BY Zlname

SELECT @BRETURN = 'FIRST'
END

ELSE


SELECT @BRETURN = 'SECOND'

END

End
Rate this:
Please Sign up or sign in to vote.

Solution 2

Since solution 1 apparently wasn't clear enough:

Remove this line:
GridView1.DataSourceID = "SqlDataSource1";
Replace it with:
GridView1.DataSource = daas;
GridView1.DataBind();

BaseDataBoundControl.DataSourceID Property (System.Web.UI.WebControls) | Microsoft Docs[^]
ASP.NET - What is the difference of DataSourceID and DataSource? - Stack Overflow[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100