Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在jqGrid中单击行时获取列的值_C#_Asp.net_Jqgrid_Jqgrid Asp.net - Fatal编程技术网

C# 在jqGrid中单击行时获取列的值

C# 在jqGrid中单击行时获取列的值,c#,asp.net,jqgrid,jqgrid-asp.net,C#,Asp.net,Jqgrid,Jqgrid Asp.net,我正在使用Asp.Net/C#,在我的一个页面中,我正在使用jqGrid向Admin显示用户列表,jqGrid包含以下列 用户代码 名字 中间名 姓 电子邮件 这是我的标记 <cc1:JQGrid ID="ModifyAccountUserDetailsjqGrid" AppearanceSettings-Caption="User Details" runat="server" Width=800 DataSourceID=ModifyAccountDataSo

我正在使用
Asp.Net/C#
,在我的一个页面中,我正在使用
jqGrid
Admin
显示用户列表,
jqGrid
包含以下列

  • 用户代码
  • 名字
  • 中间名
  • 电子邮件
  • 这是我的标记

    <cc1:JQGrid ID="ModifyAccountUserDetailsjqGrid"    AppearanceSettings-Caption="User Details"         runat="server" Width=800   DataSourceID=ModifyAccountDataSource>
        <Columns>
        <cc1:JQGridColumn HeaderText="User Code" ShowToolTip=false   PrimaryKey=true    DataField="UserCode"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="First Name" ShowToolTip=false    DataField="FirstName"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="Middle Name" ShowToolTip=false   DataField="MiddleName"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="Last Name" ShowToolTip=false     DataField="LastName"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="Email"  ShowToolTip=false        DataField="Email"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="Contact No" ShowToolTip=false    DataField="ContactNo"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="Division Name" ShowToolTip=false   DataField="DivisionName"></cc1:JQGridColumn>
        <cc1:JQGridColumn HeaderText="Last Name" ShowToolTip=false     DataField="BranchName"></cc1:JQGridColumn>
        </Columns> 
    </cc1:JQGrid>
    
    
    
    我需要的是,当管理员单击一行时,我希望获得所单击行的用户代码的值。我是jqGrid的新手,所以我不清楚如何才能做到这一点。 谁能给我指一下正确的方向吗?欢迎提出任何建议


    谢谢

    下面是一些代码,这些代码将帮助您通过修改获得案例中的用户代码

        <asp:SqlDataSource runat="server" ID="SqlDataSource1" 
        ConnectionString="<%$ ConnectionStrings:SQL2008_449777_fhsConnectionString %>" 
         SelectCommand="SELECT [OrderID], [RequiredDate], [ShipName],
          [ShipCity], [Freight] FROM [Orders]">    </asp:SqlDataSource>    
          <trirand:JQGrid runat="server" ID="JQGrid1" DataSourceID="SqlDataSource1" 
    

    请通读API

    希望这就是你想要的:


    OnSetRow事件

    首先,您应该选择与您的需求相对应的最佳回调。通常情况下,它将是
    oncetrow
    ,但在某些其他情况下,另一个回调(如
    onCellSelect
    beforeselectionrow
    ondblClickRow
    )更好

    在回调中,您将获得
    rowid
    id
    行)作为第一个参数。您可以使用
    getCell
    getRowData
    getLocalRow
    来获取某些单元格的内容。比如说

    onsetrow:function(id){
    //从“userCode”列获取数据
    var userCode=$(this).jqGrid('getCell','userCode');
    警报(用户代码);
    }
    

    onsetrow:function(id){
    var localRowData=$(this).jqGrid('getLocalRow');
    警报(localRowData.userCode);
    }
    
    如果jqGrid具有本地数据,则最后一种方法是最好的(您使用
    datatype:'local'
    或远程数据类型,如
    datatype:'json'
    loadonce:true
    结合使用)

    更新:在评论中发布了一些帖子并更新了您的问题文本后,我发现您使用的是基于jqGrid的或其他商业产品,而不是免费的开源JavaScript库。我不使用jqSuite,也不知道应该如何在jqSuite中实现JavaScript回调

    我建议您使用新的jqGrid 4.3.2功能:。你所能做的就是像这样的代码

    var $grid = jQuery("#<%= ModifyAccountUserDetailsjqGrid.ClientID %>");
    $grid.bind("jqGridSelectRow", function (id) {
        var userCode = $(this).jqGrid('getCell', 'userCode');
        alert(userCode);
    });
    
    var$grid=jQuery(“#”);
    $grid.bind(“jqGridSelectRow”,函数(id){
    var userCode=$(this).jqGrid('getCell','userCode');
    警报(用户代码);
    });
    

    var$grid=jQuery(“#”);
    $grid.bind(“jqGridSelectRow”,函数(id){
    var localRowData=$(this).jqGrid('getLocalRow');
    警报(localRowData.userCode);
    });
    

    可以在创建网格之前或之后定义事件的事件处理程序,如“jqGridSelectRow”(但是在创建id等于
    元素之后)。此外,如果需要,可以将多个事件定义为一个事件处理程序。非常实用的是,您希望在项目中为所有网格实施一些常见操作。

    最后,为了获得所需的内容,我从中获得了很多帮助,因此解决方案是在jqGrid的行选择事件中,我使用jqGrid.SelectedRow获取单元格的值

    例如:

    protected void ModifyAccountUserDetailsjqGrid_RowSelecting(object sender, Trirand.Web.UI.WebControls.JQGridRowSelectEventArgs e)
            {
                ModifyAccountUserDetailsjqGrid.SelectedRow;   
            }
    

    p.S Oleg非常感谢您的慷慨帮助。非常感谢。

    它可以工作,但它给了我一个行号的值,我需要列值。谢谢。但是我如何获得第一个单元格的值。这就是我需要的。我想可以使用ThanksgetRow、getColumn、getCell方法。我以前没有使用JqGrid的经验,但我相信,您将能够使用此功能并获取数据。我将尝试此功能并让您知道,非常感谢您的兴趣。我的.js文件中有一个问题,我只需要在onseRow:function(id){//get data from the column'userCode'var userCode=$(this).JqGrid('getCell',userCode')中编写;警报(用户代码);},或其他内容也会被激活required@freebird:
    onsetrow
    是jqGrid的选项。因此,您可以在使用
    datatype
    url
    colModel
    $(“#网格”).jqGrid({datatype:'local',
    colModel:[{'userCode'}],height:'auto',gridview:true,onsemetrow:function(id){var localRowData=$(this).jqGrid('getLocalRow');alert(localRowData.userCode)}`@freebird:看来您不仅仅在ASP.NET Web表单中使用jqGrid。你用它来代替。因此,您使用另一种产品作为您使用的问题的标签(比较)。我自己不使用jqSuite。我会在jqSuite的文档中简短地看一下,并让您知道。@freebird:不客气!听说问题解决了,我很高兴。
    var $grid = jQuery("#<%= ModifyAccountUserDetailsjqGrid.ClientID %>");
    $grid.bind("jqGridSelectRow", function (id) {
        var localRowData = $(this).jqGrid('getLocalRow');
        alert(localRowData.userCode);
    });
    
    protected void ModifyAccountUserDetailsjqGrid_RowSelecting(object sender, Trirand.Web.UI.WebControls.JQGridRowSelectEventArgs e)
            {
                ModifyAccountUserDetailsjqGrid.SelectedRow;   
            }