-1

これは私がこれまでに行ったことです(コードスニペット)

ASP.NET マークアップ:

 <div class="Grid-style">
   <asp:GridView ID="dgRequiredAttachment" runat="server" AutoGenerateColumns="false" DataKeyNames="Key">
      <Columns>
         <asp:BoundField HeaderText="Key" datafield="Key" SortExpression="Key" Visible="false"/>
          <asp:BoundField HeaderText="Value" datafield="Value" SortExpression="Value"/>
       </Columns>
    </asp:GridView>
 </div>

VB.NET コード:

 Protected Sub ddlCitizenStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCitizenStatus.SelectedIndexChanged
Dim context As New EGrantsModel.Entities
Dim attachmentType As New EGrantsModel.ATTACHMNTTYPE

Dim DC As Hashtable = New Hashtable
Dim orderCopyDesc As String = (From orderCopy In context.ATTACHMNTTYPEs Where orderCopy.ATTACHTYPEID = "1" Select orderCopy.DESCRIPTION).First
Dim notificationLtrDesc As String = (From notificationLetter In context.ATTACHMNTTYPEs Where notificationLetter.ATTACHTYPEID = "2" Select notificationLetter.DESCRIPTION).First
Dim citizenListDesc As String = (From citizenList In context.ATTACHMNTTYPEs Where citizenList.ATTACHTYPEID = "3" Select citizenList.DESCRIPTION).First

DC.Add("1", orderCopyDesc)
DC.Add("2", notificationLtrDesc)
DC.Add("3", citizenListDesc) 

dgRequiredAttachment.DataSource = DC
dgRequiredAttachment.DataBind()
dgRequiredAttachment.Visible = True

End Sub

今ラインで

Dim DC As New Hashtable = New Hashtable

したいこと: ご覧のとおり、LINQ クエリを使用して HashTable を動的に作成しています。しかし、タイプテーブルに3つ以上のエントリがある場合、テーブルAttachmentからすべての値をチェックし、ループを使用してアイテムをハッシュテーブルに入力/追加します。ATTACHMENTTypeAttachmenttypeID

誰かがこれで私を助けることができますか?

ありがとうございました

4

1 に答える 1

0

次のコードで私は私の問題を解決しました

VB コード

     Dim DC As Hashtable = New Hashtable
     Dim attachmentTypes = (From attachmentTypeData In context.ATTACHMNTTYPEs Select attachmentTypeData.DESCRIPTION, attachmentTypeData.ATTACHTYPEID)

       For Each a In attachmentTypes
         DC.Add(a.ATTACHTYPEID, a.DESCRIPTION)
       Next

      dgRequiredAttachment.DataSource = DC 
      dgRequiredAttachment.DataBind()
      dgRequiredAttachment.Visible = True
于 2012-08-07T12:16:41.680 に答える