简体   繁体   English

ASP.Net中的JQuery Flexigrid插件

[英]JQuery Flexigrid plug-in in ASP.Net

I've got an ASP.Net project with C# and have a Repeater Control on an aspx page that builds up an html table by iterating over a datasource. 我有一个使用C#的ASP.Net项目,并且在一个aspx页面上有一个Repeater控件,该页面通过遍历数据源来构建html表。 I want to use the JQuery Flexigrid plug-in to make the table scrollable, but have been unable to figure out how to make it work due to lack of documentation on the plug-in. 我想使用JQuery Flexigrid插件使该表可滚动,但是由于该插件上缺少文档,因此无法弄清楚该表如何工作。 Does anyone know how to do this, or have sample code to share? 有谁知道该怎么做,或者有示例代码可以共享?

A simple google search "asp.net+flexigrid" gave me this and this 一个简单的谷歌搜索“ asp.net + flexigrid”给了我这个这个

I must also mention that support looks to be thin on the ground for flexigrid so you maybe better looking at the better documented jqGrid 我还必须提到,flexigrid的支持似乎很少,因此您最好查看记录更好的jqGrid

I have never used Flexigrid myself however after looking at the samples on the site I'll offer my suggestions. 我自己从未使用过Flexigrid,但是在查看了网站上的示例后,我将提供建议。

It looks like what you need to create with your repeater is a properly formatted html table with at least a thead and tbody section. 看起来您需要用中继器创建的是格式正确的html表,至少包含thead和tbody部分。

<table id="mytable">
  <thead>
      <tr>
        <th>header1</th>
        <th>header2</th>
      </tr>
  </thead>
  <tbody>
      <tr>
        <td>table data 1</td>
        <td>table data 2</td>
      <tr>
  </tbody>
</table>

Once done, making a simple call to the following should create the Flexigrid table with the default settings: 完成后,只需简单调用以下内容,即可使用默认设置创建Flexigrid表:

$("#mytable").flexigrid();

From there you can pass in what looks to be a ton of options to make it look as pretty as you want. 从那里,您可以传递看起来很多的选项,以使其看起来像您想要的那样漂亮。

As for the repeater itself, there are a bunch of ways to set it up depending on what you need. 至于中继器本身,有多种方法可以根据您的需要进行设置。 Probably the simplest way is as follows: 可能最简单的方法如下:

<table>
<thead>
  <tr>
    <th><asp:label id="header1" runat="server"></asp:label></th>
    <th><asp:label id="header2" runat="server"></asp:label></th>
  </tr>
</thead>
<tbody>
<asp:repeater id="myrepeater" runat="server" OnItemDataBound="myrepeater_ItemDataBound">
  <ItemTemplate>
    <tr>
      <td><asp:label id="data1" runat="server"></asp:label></td>
      <td><asp:label id="data2" runat="server"></asp:label></td>
    </tr>
  </ItemTemplate>
</asp:repeater>
</tbody>
</table>

And your data bind event would look something like this: 您的数据绑定事件将如下所示:

public void myrepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  myDataObject = e.Item.DataItem;
  Label data1 = e.Item.FindControl("data1");
  Label data2 = e.Item.FindControl("data2");

  data1.Text = myDataObject.data1;
  data2.Text = myDataObject.data2;
}

Don't try to reference the table by id , you're better off using a class to identify the table. 不要尝试通过id引用表,最好使用一个类来标识表。 If you look at the page source you'll see that the table id isn't mytable - it's mangled by ASP.NET depending on your page structure. 如果查看页面源,您会发现表ID不是mytable会根据您的页面结构对其进行重整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM