hello everyone ;
the question is, my gridview are not display in the webform. this is my code. there is no error in my code, but gridview are not display.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_grid_doctor();
}
}
protected void Button_show_Click(object sender, EventArgs e)
{
load_grid_doctor();
}
public void load_grid_doctor()
{
SqlCommand cmd = new SqlCommand("select * from [doctor]",connection.get());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.SelectCommand=cmd;
da.Fill(ds);
GridView_doctor.DataSource = ds;
GridView_doctor.DataBind();
}
}
regards
sumaira
Loading

Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 4, 2011, 3:24 AM EDT
If you have written the below code in gridview as
AutoGenerateColumns="false" then change it to
AutoGenerateColumns="True"
Your code is ok.
Thanks
If this post helps you mark it as answer
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Sep 4, 2011, 3:44 AM EDT
there is no effect of AutoGenerateColumns="true" in my code. sir , this is my real code.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_grid_doctor();
}
}
protected void Button_show_Click(object sender, EventArgs e)
{
load_grid_doctor();
}
public void load_grid_doctor()
{
SqlCommand cmd = new SqlCommand("select * from [doctor]",connection.get());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.SelectCommand=cmd;
da.Fill(ds);
GridView_doctor.DataSource = ds;
GridView_doctor.DataBind();
}
}
and in the asp.net plateform, i placed some labels and textbox and one gridview in the webform. after this i rum code . this is my code of asp.net
regards
sumaira
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 4, 2011, 4:18 AM EDT
Try this
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_grid_doctor();
}
}
public void load_grid_doctor()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
//SqlCommand cmd = new SqlCommand("select * from [doctor]", connection.get());
SqlCommand cmd = new SqlCommand("select * from t2",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "t2");
//da.SelectCommand = cmd;
da.Fill(ds,"t2");
GridView_doctor.DataSource = ds;
GridView_doctor.DataMember = "t2";
GridView_doctor.DataBind();
con.Close();
}
protected void Button_show_Click(object sender, EventArgs e)
{
//load_grid_doctor();
}
}
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Sep 4, 2011, 4:29 AM EDT
sir, why you closed "load_grid_doctor" in show button. because if i insert some information via insert query then how i can see my desire information.
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Sep 4, 2011, 4:41 AM EDT
why i used connection string in the start of the code. because i make a separate connection class like this .
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 4, 2011, 4:56 AM EDT
I have not created connection class in my system.So iam writing it.As you have created it ,accordingly you change it.
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 4, 2011, 5:11 AM EDT
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 4, 2011, 10:04 PM EDT
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Sep 5, 2011, 10:44 PM EDT
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Sep 5, 2011, 11:02 PM EDT
i am sending u my code file .can u check this. after this code , my gridview is not displaying.
regards
sumaira
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 5, 2011, 11:24 PM EDT
The Problem is with Select Query.
In your markup language, you Set GridView DataField to Various names, So use your Select query to alias in name with datafield. Like this
Select doctoorid as doctor id , userid as user id, name as name, days as days, timing as timing from table.
the Alias names in query should match your Datafield in gridview.
I attached my Source Code Here. Its Working. See it.
----------------------------------------
If this helps you, mark it as "Correct Answer"
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 6, 2011, 12:03 AM EDT
There might be space in the bound filed i saw check it
Thanks
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 9, 2011, 11:26 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts