【问题标题】:Delete Datalist row with multiple primary keys删除具有多个主键的 Datalist 行
【发布时间】:2010-09-06 08:58:51
【问题描述】:

我有一个带有 OnDeleteCommand="Delete_Command" 的数据列表。

我想要删除具有多个主键的记录,但我不知道如何从 Delete_Command 事件中访问它。

如果我使用 DataKeyField,我只能使用一个键。 有什么解决方法吗?

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    哦,对不起,我错过了。

    AFAIK 默认情况下没有这种可能性。也许你可以从你的主键创建一个复合键,比如

    Key1UnderscoreKey2UnderscoreKey3

    并在事件处理程序中拆分它。所以这是 DataList 的 DIY 多键处理程序 :-)

    编辑:下划线在格式化过程中丢失,它替换为斜体文本。所以不要使用“下划线”这个词,而是使用真正的下划线

    【讨论】:

      【解决方案2】:

      您可以访问所有密钥:

      gridView.DataKeys[rowNum][dataKeyName]
      

      其中 rowNum 是来自 gridView_RowDeleting 事件处理程序的 e.RowIndex,而 dataKeyName 是您要获取的键:

      <asp:GridView ID="gridView" runat="server" DataKeyNames="userid, id1, id2, id3" OnRowDeleting="gridView_RowDeleting">
      
      protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
      {
          gridView.DataKeys[e.RowIndex]["userid"]...
          gridView.DataKeys[e.RowIndex]["id1"]...
          gridView.DataKeys[e.RowIndex]["id2"]...
          gridView.DataKeys[e.RowIndex]["id3"]...
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-10
        • 2014-07-18
        • 1970-01-01
        • 2013-07-10
        • 1970-01-01
        相关资源
        最近更新 更多