
脚本没指定获取到的类型的话,通常是object{id:value,name:value} 这种样式的,这里注意了:用浏览器后台断点,查看一下ID的名称,不是每个都是rowsid的,而且getSelected只能获取到一组你选中的数据
在中多数据绑定的控件很多 论功能来说 应该属DataGrid最为齐全 但它没有提供现成的显示记录序号的功能 不过我们可以通过它所带的一些参数来间接得到序号 下面来看看怎样得到和显示序号值计算方式如下
( )在后台
DataGrid CurrentPageIndex DataGrid PageSize + e Item ItemIndex +
( )在前台
DataGrid CurrentPageIndex DataGrid PageSize + Container ItemIndex +
说明
e表示System Web UI WebControls DataGridItemEventArgs参数类的实例
DataGrid 这里表示前台的一个实例
DataGrid CurrentPageIndex 获取或设置当前显示页的索引
DataGrid PageSize 获取或设置要在 DataGrid 控件的单页上显示的项数
下面我使用了 种方法来在前台显示序号 不过都是围绕上面的计算式展开
( ) 使用DataGrid的ItemCreated设置值 而前台的单元格可以是绑定列或者模板列(包括空模板)
( ) 使用DataGrid的ItemDataBound设置值 而前台的单元格可以是绑定列或者模板列(包括空模板)
( ) 在前台直接绑定计算表达式
( ) 在后台类中编写方法计算表达式由前台页面类继承调用
备注 在数据库中获取数据时设置额外的序号列这里不做讨论 我认为这是最糟糕的实现方法
下面以获取Northwind数据库的Customers表的数据为列 显示如下
序号
序号
序号
序号
序号
CustomerID
LONEP
MAGAA
MAISD
MEREP
MORGK
NORTS
OCEAN
OLDWO
OTTIK
PARIS
下面是WebFormPaging aspx文件代码
<%@ Page language= c# Codebehind= WebFormPaging aspx cs AutoEventWireup= false Inherits= AspnetPaging WebForm %>
<!DOCTYPE HTML PUBLIC //W C//DTD HTML Transitional//EN >
<HTML>
<HEAD>
<title>WebForm </title>
<meta content= Microsoft Visual Studio NET name= GENERATOR >
<meta content= C# name= CODE_LANGUAGE >
<meta content= JavaScript name= vs_defaultClientScript >
<meta content= name= vs_targetSchema >
</HEAD>
<body>
<form id= Form method= post runat= server >
<TABLE id= Table cellSpacing= cellPadding= width= align= center border= >
<TR>
<TD><asp:datagrid id= DataGrid runat= server AutoGenerateColumns= False Width= % AllowPaging= True >
<Columns>
<asp:BoundColumn HeaderText= 序号 ></asp:BoundColumn>
<asp:TemplateColumn HeaderText= 序号 ></asp:TemplateColumn>
<asp:TemplateColumn HeaderText= 序号 >
<ItemTemplate>
<asp:Label ID= itemIndex runat= server ></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText= 序号 >
<ItemTemplate>
<%# (DataGrid CurrentPageIndex DataGrid PageSize + Container ItemIndex + ) %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText= 序号 >
<ItemTemplate>
<%# GetRecordIndex( Container ItemIndex ) %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField= CustomerID HeaderText= CustomerID ></asp:BoundColumn>
</Columns>
<PagerStyle Mode= NumericPages ></PagerStyle>
</asp:datagrid></TD>
</TR>
<TR>
<TD></TD>
</TR>
<TR>
<TD></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
后台WebFormPaging aspx cs代码如下
using System;
using System Collections;
using System ComponentModel;
using System Data;
using System Drawing;
using System Web;
using System Web SessionState;
using System Web UI;
using System Web UI WebControls;
using System Web UI HtmlControls;
namespace AspnetPaging
{
public class WebForm : System Web UI Page
{
private int recordCount = ;
protected System Web UI WebControls DataGrid DataGrid ;
private void Page_Load(object sender System EventArgs e)
{
if(!Page IsPostBack)
{
DataGridDataBind();
}
}
//绑定数据
private void DataGridDataBind()
{
DataSet ds = DataAccess GetCustomersData();
this DataGrid DataSource = ds;
this DataGrid DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 不要使用代码编辑器修改
/// 此方法的内容
/// </summary>
private void InitializeComponent()
{
this DataGrid ItemCreated += new System Web UI WebControls DataGridItemEventHandler(this DataGrid _ItemCreated);
this DataGrid PageIndexChanged += new System Web UI WebControls DataGridPageChangedEventHandler(this DataGrid _PageIndexChanged);
this DataGrid ItemDataBound += new System Web UI WebControls DataGridItemEventHandler(this DataGrid _ItemDataBound);
this Load += new System EventHandler(this Page_Load);
}
#endregion
//翻页
private void DataGrid _PageIndexChanged(object source System Web UI WebControls DataGridPageChangedEventArgs e)
{
DataGrid CurrentPageIndex = e NewPageIndex;
DataGridDataBind();
}
//获取当前项
protected int GetRecordIndex(int itemIndex)
{
return (DataGrid CurrentPageIndex DataGrid PageSize + itemIndex + );
}
private void DataGrid _ItemCreated(object sender System Web UI WebControls DataGridItemEventArgs e)
{
DataGrid dg = (DataGrid)sender;
if(e Item ItemType == ListItemType Item || e Item ItemType == ListItemType AlternatingItem)
{
e Item Cells[ ] Text = (dg CurrentPageIndex dg PageSize + e Item ItemIndex + ) ToString();
e Item Cells[ ] Text = (dg CurrentPageIndex dg PageSize + e Item ItemIndex + ) ToString();
}
}
private void DataGrid _ItemDataBound(object sender System Web UI WebControls DataGridItemEventArgs e)
{
DataGrid dg = (DataGrid)sender;
if(e Item ItemType == ListItemType Item || e Item ItemType == ListItemType AlternatingItem)
{
((Label)e Item FindControl( itemIndex )) Text = (dg CurrentPageIndex dg PageSize + e Item ItemIndex + ) ToString();
}
}
}
数据层代码如下
using System;
using System Data;
using System Data SqlClient;
using System Configuration;
namespace AspnetPaging
{
public class DataAccess
{
private static string connString = ConfigurationSettings AppSettings[ ConnString ];
private DataAccess()
{
}
public static DataSet GetCustomersData()
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand m = new SqlCommand( GetCustomers conn);
m CommandType = CommandType StoredProcedure;
SqlDataAdapter dataAdapter = new SqlDataAdapter(m);
DataSet ds = new DataSet();
dataAdapter Fill(ds);
return ds;
}
}
}
lishixinzhi/Article/program/net/201311/12926
比如你的th是这样写的<th data-option="field: 'xxx', title: 'xxx',formatter: "testFormat"">
然后那个testFormat就可以单独拿出来写在js里面了。。。
js里面就可以写 function testformat((value,row,index){ }
直接变成js的知识了 ,后面你就应该知道如何取formatter里面的值了吧。。。
1、首先写入导出按钮和需要导出的datagrid列表。
2、点击导出按钮;获得需要导出的字段与不需要导出的数据进行数据处理,并且进行json解析。
3、异步 *** 作进入后台获取数据。
4、后台将数据写入excel(其中还有一个帮助类)。
你三个地方的productType不是同一个变量,所以你combobox的url中的值永远为undefined。
我做项目也遇到要js全局变量问题,但设置的全局变量,function中好像没法用,他会自己定义这个变量,所以你三个地方的productType不是你认为的同一个。
互相探讨,希望可以解决!
var width = $(window)width()-80;
var height = $(window)height()-120;
stView_layout = $('#stView_layout')layout({
width: width,
height: height
});
station_view = $('#stationView')window({
title: '测站导航',
left:50,
top:80,
width: width,
modal: false,
shadow: false,
closed: true,
height: height,
onResize:function(w,h){
if(stView_treegrid){
stView_treegridtreegrid({
width:w-20,
height:h-260
});
}
}
});
你好!!
先排除是否是返回JSON字符串不正确造成的!
on":"似算计"},]}---->>>
on":"似算计"}]}
以上就是关于Easyui 问题 :var row=$('#dg').datagrid('getSelected');获取不到全部的内容,包括:Easyui 问题 :var row=$('#dg').datagrid('getSelected');获取不到、asp.net中显示DataGrid控件列序号的几种方法、怎么获取 EasyUi datagrid 中 formatter 后的 值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)