如何使用javascript或jquery将值绑定到asp gridview或listview。 [英] How to bind value to asp gridview or listview using javascript or jquery.

查看:53
本文介绍了如何使用javascript或jquery将值绑定到asp gridview或listview。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript或jquery将值绑定到datalist或gridview。



我使用了web方法和jquery将值绑定到gridview。为此,我使用了webmethod,我的web方法将返回一个包含其中所有值的列表,我已经使用jquery来调用方法,并且值正在成功传递但是当我将值绑定到我的asp gridview时它不会抛出任何错误,但价值没有约束力。



以下是代码。价值在变量细节中完美呈现



成功:

How to bind value to datalist or gridview using javascript or jquery.

I have used the web method and jquery to bind the value to the gridview. For doing this i have used webmethod and my web method will return a list with all the values in it and i have used jquery to call the method and the value is comming successfully but when i bind the value to my asp gridview it is not throwing any error but the value is not binding.

The following is the code. And the value is comming perfectly in the variable details

success:

function (details)
 { $("#<%=GridView1.ClientID %>").append(details.d); }







所有功能都成功执行但我的网格没有显示。

我的完整解决方案是



公共部分类WebForm3:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{





}

[WebMethod]

public static Name [] LoadValues()

{

SqlConnection conn = new SqlConnection(@Data Source = CLAYSYSCH0028 \ Sharepoint; Initial Catalog = ShankarMS; Integrated Security = True);

conn.Open();

List< name> list = new List< name>();

SqlCommand comm = new SqlCommand();

comm.CommandText =select * from UserDetails;

comm.Connection = conn;

SqlDataAdapter adapter = new SqlDataAdapter(comm);

DataSet set = new DataSet();

adapter.Fill(set);

DataTable table = set.Tables [0];

foreach(table.Rows中的DataRow行)

{

名称n =新名称();

n.names = row [FirstName]。ToString();

list。添加(n);

}

返回list.ToArray();

}

}

公共类名称

{

公共字符串名称

{

get;

设定;

}

}


绑定到网格视图的
jquery






All the functions are executing successfully but my grid is not showing.
My complete solution is

public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
[WebMethod]
public static Name[] LoadValues()
{
SqlConnection conn = new SqlConnection(@"Data Source=CLAYSYSCH0028\Sharepoint;Initial Catalog=ShankarMS;Integrated Security=True");
conn.Open();
List<name> list = new List<name>();
SqlCommand comm = new SqlCommand();
comm.CommandText = "select * from UserDetails";
comm.Connection = conn;
SqlDataAdapter adapter = new SqlDataAdapter(comm);
DataSet set = new DataSet();
adapter.Fill(set);
DataTable table = set.Tables[0];
foreach (DataRow row in table.Rows)
{
Name n = new Name();
n.names = row["FirstName"].ToString();
list.Add(n);
}
return list.ToArray();
}
}
public class Name
{
public string names
{
get;
set;
}
}

jquery for binding to grid view

<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                url: "WebForm3.aspx/LoadValues",
                data: "{}",
                contentType: "application/json",
                dataType: "json",
                success: function (data) {

                    for (var i = 0; i < data.d.length; i++) {



                        $("#<%=GridView1.ClientID %>").append("<tr><td>" + data.d[i].names + "</td></tr>");
                    }

                },
                Error: function () {
                    debugger;
                }

            })
        });

    </script>









Asp Grid View







Asp Grid View

<asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True">
        </asp:GridView>

推荐答案

#<%= GridView1 .ClientID%>)。append(details.d); }
("#<%=GridView1.ClientID %>").append(details.d); }







所有功能都成功执行但我的网格没有显示。

我的完整解决方案是



公共部分类WebForm3:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{





}

[WebMethod]

public static Name [] LoadValues()

{

SqlConnection conn = new SqlConnection(@Data Source = CLAYSYSCH0028 \ Sharepoint; Initial Catalog = ShankarMS; Integrated Security = True);

conn.Open();

List< name> list = new List< name>();

SqlCommand comm = new SqlCommand();

comm.CommandText =select * from UserDetails;

comm.Connection = conn;

SqlDataAdapter adapter = new SqlDataAdapter(comm);

DataSet set = new DataSet();

adapter.Fill(set);

DataTable table = set.Tables [0];

foreach(table.Rows中的DataRow行)

{

名称n =新名称();

n.names = row [FirstName]。ToString();

list。添加(n);

}

返回list.ToArray();

}

}

公共类名称

{

公共字符串名称

{

get;

设定;

}

}


绑定到网格视图的
jquery






All the functions are executing successfully but my grid is not showing.
My complete solution is

public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
[WebMethod]
public static Name[] LoadValues()
{
SqlConnection conn = new SqlConnection(@"Data Source=CLAYSYSCH0028\Sharepoint;Initial Catalog=ShankarMS;Integrated Security=True");
conn.Open();
List<name> list = new List<name>();
SqlCommand comm = new SqlCommand();
comm.CommandText = "select * from UserDetails";
comm.Connection = conn;
SqlDataAdapter adapter = new SqlDataAdapter(comm);
DataSet set = new DataSet();
adapter.Fill(set);
DataTable table = set.Tables[0];
foreach (DataRow row in table.Rows)
{
Name n = new Name();
n.names = row["FirstName"].ToString();
list.Add(n);
}
return list.ToArray();
}
}
public class Name
{
public string names
{
get;
set;
}
}

jquery for binding to grid view

<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">


(document).ready(functio n(){
(document).ready(function () {


.ajax({
type:POST,
url:WebForm3.aspx / LoadValues,
data: {},
contentType:application / json,
dataType:json,
success:function(data){

for(var i = 0; i < data.d.length; i ++) {



< span class =code-attribute>
.ajax({ type: "POST", url: "WebForm3.aspx/LoadValues", data: "{}", contentType: "application/json", dataType: "json", success: function (data) { for (var i = 0; i < data.d.length; i++) {


这篇关于如何使用javascript或jquery将值绑定到asp gridview或listview。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆