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 NayakPosted Sep 9, 2011, 3:26 PM
Satyapriya NayakPosted Sep 6, 2011, 4:03 AM
There might be space in the bound filed i saw check it
Thanks
Prabhu RajaPosted Sep 6, 2011, 3:24 AM
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"
sumaira manzoor hussain khanPosted Sep 6, 2011, 3:02 AM
i am sending u my code file .can u check this. after this code , my gridview is not displaying.
regards
sumaira
sumaira manzoor hussain khanPosted Sep 6, 2011, 2:44 AM
Prabhu RajaPosted Sep 5, 2011, 2:04 AM
Satyapriya NayakPosted Sep 4, 2011, 9:11 AM
Satyapriya NayakPosted Sep 4, 2011, 8:56 AM
I have not created connection class in my system.So iam writing it.As you have created it ,accordingly you change it.
sumaira manzoor hussain khanPosted Sep 4, 2011, 8:41 AM
why i used connection string in the start of the code. because i make a separate connection class like this .
sumaira manzoor hussain khanPosted Sep 4, 2011, 8:29 AM
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.
Satyapriya NayakPosted Sep 4, 2011, 8:18 AM
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 khanPosted Sep 4, 2011, 7:44 AM
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 NayakPosted Sep 4, 2011, 7:24 AM
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