-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,它会检查ATTACHMENTType表中的所有值,AttachmenttypeID并使用循环将项目填充/添加到哈希表。

有人可以帮我弄这个吗?

谢谢

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 回答