【问题标题】:how to get the Selected item in dropdownlist while click the Edit button in inline kendo grid in asp如何在asp中单击内联剑道网格中的编辑按钮时获取下拉列表中的选定项目
【发布时间】:2014-11-02 18:47:24
【问题描述】:

如何在单击编辑按钮时在 Kendo Grid 中显示数据库中的选定项目 **我喜欢的编码**

var grid= $("#DivUser").kendoGrid(
{
dataSource: DataSource4,
scrollable: true,
sortable: true,
filterable: false,
reorderable: true,
resizable: true,
pageable: true,
toolbar: [ { text : "Add new record", name: "popup",
iconClass: "k-icon k-add"} ],
editable : {
mode : "inline"
columns: [

                {
                    field: "LoginName",
                    title: "Login Name",
                    width:"175px"
                },


                     {
                    field: "ScopeId",
                    title: "Scope Id",
                    editor: ScopeDropDownEditor
},

{
command: ["edit", "destroy"],
title: " ",
width: "175px"
}
]
}).data("kendoGrid");

var DataSourceScope = new kendo.data.DataSource( { 传输: { 读取: { url: "WebServices/Project.asmx/GetScope", data: "{}", contentType: '应用/json; charset=utf-8', type: 'POST', dataType: 'json' }, parameterMap: function(options, operation) { if (operation == 'read') return kendo.stringify(options); } }, schema: { data: function(Data) { @987654364 @return (Data.d); }, 型号: { id: "ScopeId", 字段: { ScopeId: { type: "number"}, ScopeName: { 类型:“字符串”} } } }, 错误:函数(e) {<br> var xhr = e[0]; var statusCode = e[1]; var errorThrown = e[2]; alert('DataSourceScope - ' + xhr + ', ' + statusCode + ', ' + errorThrown); }<br> }) ; function ScopeDropDownEditor(container, options) { $(' data-bind="value:' + options.field + '"/>') .appendTo(container) .kendoDropDownList( { autoBind: false, dataSource: DataSourceScope }); } `

在我的网络服务代码中

 public class Scopes
  {
      int _ScopeId;
      string _ScopeName;

      public int ScopeId
      {
          get { return _ScopeId; }
          set { _ScopeId = value; }
      }

      public string ScopeName
      {
          get { return _ScopeName; }
          set { _ScopeName = value; }
      }

      public Scopes() { }

      public Scopes(int ScopeId, string ScopeName) { this.ScopeId = ScopeId; this.ScopeName = ScopeName; }



}

  [WebMethod]
  public List<Scopes> GetScope()
  {

      string StrConnectionString = ConfigurationManager.ConnectionStrings["sample"].ConnectionString;
      SqlConnection SqlConnection1 = new SqlConnection(StrConnectionString);
      SqlCommand SqlCommand1 = new SqlCommand("select distinct ScopeId,(select ScopeName from Scope2 where Scope2.ScopeID=User2.ScopeId)as ScopeName from User2", SqlConnection1);

      DataTable DataTable1 = new DataTable();
      SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(SqlCommand1);
      SqlDataAdapter1.Fill(DataTable1);

      List<Scopes> ListScope = new List<Scopes>();
      foreach (DataRow DataRow1 in DataTable1.Rows)
      {
          ListScope.Add(new Scopes(Convert.ToInt32(DataRow1["ScopeId"]), Convert.ToString(DataRow1["ScopeName"])));
      }

      return ListScope;

  }

没关系.. 但是在单击编辑按钮后,下拉列表项目如第一项 例如

ScopeName id 下拉列表 项目管理员、开发人员、测试人员

在数据库中 james 是测试员 如果我点击编辑按钮意味着

Name ScopeName
James admin
developer
tester

如何绑定以及如何显示选定的项目? 提前谢谢。

【问题讨论】:

    标签: javascript asp.net kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    编辑

    直接使用java脚本获取数据

     var xhReq = new XMLHttpRequest();
     xhReq.open("POST", 'WebServices/Project.asmx/GetScope', false);
     xhReq.send(null);
     var DataSourceScope = JSON.parse(xhReq.responseText);
    
     function ScopeDropDownEditor(container, options) 
        {
        $('<input name="' + options.field + '"/>').appendTo(container).kendoDropDownList({
                                dataTextField: "ScopeName",
                                dataValueField: "ScopeId",
                                dataSource: DataSourceScope.d
    
                            });
        } 
    

    【讨论】:

    • 它不会出现 :( 我只使用了上面的编码... web 服务返回范围 id 和范围名称,例如 1 个管理员、2 个开发人员、3 个测试人员
    • 检查您的 DataSourceScope 是否具有 [{ScopeId:'',ScopeName:''},{..},..] 格式的值
    • 您是否使用自定义模板弹出??
    • 我不明白你能给我一个解决方案吗,我正在使用内联编辑来编辑功能。
    猜你喜欢
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    相关资源
    最近更新 更多