bind gridview using jquery

Posted by Klbaiju under jQuery on 9/24/2014 | Points: 10 | Views : 743 | Status : [Member] | Replies : 0
Hi,

in my application i want to bind gridview by jquery .

problem iam facing is i don't know the fieldnames because i want to execute a query.

how it is possible.following is a working code if we know the field names..

i want to do like following query. any possibility

public class bdetails
{
public string bus_id { get; set; }
public string bus_name { get; set; }
public string model { get; set; }

}

---------------------------------------------------------------------------------------------------
[WebMethod]
public static bdetails[] BindGrid()
{
string msg = "";
DataTable dt = new DataTable();
List<bdetails> details = new List<bdetails>();
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=baiju;User ID=baijuserver;Password=baiju123kl"))
{
string strquery = "select * from busmaster";
using (SqlCommand cmd = new SqlCommand(strquery, con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
bdetails user = new bdetails();
user.bus_id = dtrow["bus_id"].ToString();
user.bus_name = dtrow["bus_name"].ToString();
user.model = dtrow["model"].ToString();
details.Add(user);
}
con.Close();
}
}
return details.ToArray();

}
----------------------------------
private void BindColumnToGridview()
{
DataTable dt = new DataTable();
dt.Columns.Add("bus_id");
dt.Columns.Add("bus_name");
dt.Columns.Add("model");
dt.Rows.Add();
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Rows[0].Visible = false;
}

-----------------------------------------
if (!IsPostBack)
{

BindColumnToGridview();
}

--------------------------------------------------------------
for (var i = 0; i < data.d.length; i++) {
$("#GridView1").append("<tr class='gd1'><td>" + data.d[i].bus_id + "</td><td>" + data.d[i].bus_name + "</td><td>" + data.d[i].model + "</td><td>"</tr>");

}

Regards

Baiju




Responses

(No response found.)

Login to post response