从多个表中获取数据 [英] Get Data From Multiple Tables

查看:87
本文介绍了从多个表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在使用MVC 2.0.

我有一个问题,我想在视图中获取两个表的数据.

需要来自table1的数据来填充我的网格.

以及来自表2的数据,以向用户提供我在另一个表中拥有的项目的选择(我希望将项目显示为复选框以供选择).
我不知道该怎么做.

hello friends,
I am using MVC 2.0.

I have a problem that I want to get data in my view for two tables.

data from table1 is needed to fill my grid.

and data from table 2 to provide user the choices of items that i have in another table(I want to show item as checkbox for selecting).
I have no idea how can I do this task.

can you please help me on this.

推荐答案

为什么不使用JOIN子句将两个表连接在一起.如果要一起显示相关的表数据,则必须有两个表都应具有的键.
Why don''t you join the two tables using a JOIN clause. If you want to show related table data together, there must be a key that should be common to both tables.


Neo Arora写道:
Neo Arora wrote:

和表2中的数据为用户提供了我在另一个表中的项目选择(我想将项目显示为用于选择的复选框)

and data from table 2 to provide user the choices of items that i have in another table(I want to show item as checkbox for selecting)



如果您有两个以上的选择,将很难使用CheckBox表示它们.您是否认为使用ComboBox会更好?



If you have more than two choices it is going to be very difficult to use a CheckBox to represent them. Do you not think that you would be better to use a ComboBox?




实际上,普通的html代码不支持选中的列表框.所以我们的需求不是正常情况.

请尝试这个.

在控制器中

Hi,

Actually normal html code doesn''t support checked list box. So ur need is not get by normal condition.

Please try this.

in controller

Function CheckBox() As ActionResult

            Dim strCheckBoxGroup As String
            strCheckBoxGroup = "<table border='1'> "
            For x As Integer = 1 To 10
                strCheckBoxGroup = strCheckBoxGroup + " <tr> "
                strCheckBoxGroup = strCheckBoxGroup + " <td> "
                strCheckBoxGroup = strCheckBoxGroup + " <input id='" + x.ToString + "' name='" + x.ToString + "' type='checkbox' value='true' />"
                strCheckBoxGroup = strCheckBoxGroup + x.ToString + " Description "
                strCheckBoxGroup = strCheckBoxGroup + " </td> "
                strCheckBoxGroup = strCheckBoxGroup + " </tr> "
            Next
            strCheckBoxGroup = strCheckBoxGroup + " </table>"
            ViewData("chkBox") = New HtmlString(strCheckBoxGroup)
            Return View(ViewData("chkBox"))
        End Function




视图中




In View

<body>
<%
    Html.BeginForm()
    If True Then
    %>
    <div>
        <%: ViewData("chkBox")%>
    </div>
    <% End If%>

</body>


这篇关于从多个表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆