i want to display the details using Grid view?

Posted by Tejamanimala under ASP.NET on 3/21/2013 | Points: 10 | Views : 1761 | Status : [Member] | Replies : 5
hi,i have a page,in which i want to display the student tails from registration table,and marks,date from results table.
i wrote the code ,can any one tell me is this code correct or not?because the gridview is not displaying when i run it?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace newonlineexam
{
public partial class ExamDetailsAdmin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;database=Database1.mdf;Data Source=IPOG-A95E1056D3");
protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from ExamDetails", con);
DataSet ds = new DataSet();
da.Fill(ds, "ExamDetails");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
}

manimala


Responses

Posted by: Satyapriyanayak on: 3/21/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from ExamDetails", con);
DataSet ds = new DataSet();
da.Fill(ds, "ExamDetails");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}

If this post helps you mark it as answer
Thanks

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/21/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Try this Code
//your WebConfig File.
//<add name="CntString" connectionString="Data Source=PCNAME;Initial Catalog=DatabaseName;User ID=SqlUserID;Password=SqlPwd" providerName="System.Data.SqlClient" />

//Server Side C# Code
//Read WebConfig.
string strConnString = ConfigurationManager.ConnectionStrings["CntString"].ConnectionString;
//Inline Code
//SqlConnection objconn = new SqlConnection("Data Source=PCNAME;Initial Catalog=DBNAME;User ID=SqlUserId;Password=DBPWd");
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid("Select * from Tbl_Emp");
}
}
void bindgrid(string Qry)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = Qry;


com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
Grd1.DataSource = ds;
Grd1.DataBind();

con.Close();

}


Client Side
================

<asp:GridView ID="Grd1" runat ="server" AutoGenerateColumns ="false">

<Columns>
<asp:TemplateField HeaderText="EmpName">
<ItemTemplate>
<asp:Label ID="lblEmpname" runat ="server" Text ='<%# Bind("EmpName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="EmpNo">
<ItemTemplate>
<asp:Label ID="lblEmpNo" runat ="server" Text ='<%# Bind("EmpId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>




</Columns>
</asp:GridView>

Mark as Answer if its helpful to you

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tejamanimala on: 3/22/2013 [Member] Starter | Points: 25

Up
0
Down

hi,i have a page,in which i want to display the student tails from registration table,and marks,date from results table.
i wrote the code ,can any one tell me is this code correct or not?because the gridview is not displaying when i run it?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace newonlineexam
{
public partial class StudentDetailsAdmin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;Data Source=EKTHA-3D34;Initial Catalog=OnlineExam");
protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select s1.UserID,s1.FirstName,s1.LastName,s1.Address,s1.ContactNo,s1.DOB,s1.Gender,s1.EmailID,r1.Date,r1.Marks from Registration s1,Resultsforstudents r1 INNER JOIN Results r1 ON s1.UserID=r1.UserID", con);
DataSet ds = new DataSet();
da.Fill(ds, "Registration");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}


}
}

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/22/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

debug your code Dataset return or not otherwise ur project file attached zip format then i will solved ur issue.

Mark as Answer if its helpful to you

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/22/2013 [Member] Starter | Points: 25

Up
0
Down
hello
replace ur code with this
namespace newonlineexam

{
public partial class ExamDetailsAdmin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;database=Database1.mdf;Data Source=IPOG-A95E1056D3");
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
fillgrid();
}
}

public void fillgrid()
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from ExamDetails", con);
DataSet ds = new DataSet();
da.Fill(ds, "ExamDetails");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
}


Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response