#eval内部联接表 [英] #Eval for inner joined table

查看:75
本文介绍了#eval内部联接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql查询,内部连接两个表,我的asp页上有griview.有没有办法使用<%#Eval%>从内部联接表中获取值.例如<%#Eval("inner_joined_table_name.column_name")%>

Hi, i have a mysql query that inner joins two tables and i have griview on my asp page. Is there way to get a value from the inner joined table using <%# Eval %>. For example <%# Eval ("inner_joined_table_name.column_name")%>

推荐答案

是!

Eval将在查询结果中查找该列.只要确保您的查询在连接表后获取列即可.


更新:
根据您的要求:
我确实有一个包含以下字段的gridview:
Yes!

Eval will look for the column in the query result. Just make sure that your query fetches the column after the join of tables.


UPDATE:
based on what you ask:
I do have a gridview with the following fields:
<asp:Label ID="Desc" runat="server" Text='<%# Eval("description") %>'/> 
<asp:Label runat="server" ID="Type" Text='<%# Eval("description")%>'/>
The first field is fine and it gets the description from the first table, the second field needs to get the description from the inner joined table. My query looks like this:
        MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT rank_distribution.rank_distribution_id,rank_distribution.description ,rank_distribution.amount,transaction_distribution.description FROM rank_distribution INNER JOIN transaction_distribution ON transaction_distribution.transaction_distribution_id = rank_distribution.transaction_distribution_id WHERE rank_distribution.rank_transaction_type_id = @rank_transaction_type_id", con);
        cmd.Parameters.AddWithValue("@rank_transaction_type_id", Request.QueryString["rank_transaction_type_id"]);



您需要做的就是为列名添加别名,以便在末尾清楚地标识两个描述列.

试试:



All you need to do is to have alias of the column names such that there are two description columns clearly identifiable at the end.

Try:

<asp:Label ID="Desc" runat="server" Text='<%# Eval("RD_description") %>'/> 
<asp:Label runat="server" ID="Type" Text='<%# Eval("TD_description")%>'/>


查询:


Query:

MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT rank_distribution.rank_distribution_id,rank_distribution.description as RD_description,rank_distribution.amount,transaction_distribution.description as TD_description FROM rank_distribution INNER JOIN transaction_distribution ON transaction_distribution.transaction_distribution_id = rank_distribution.transaction_distribution_id WHERE rank_distribution.rank_transaction_type_id = @rank_transaction_type_id", con);


Eval(摘自文档 [ ^ ])-
从容器对象到要放置在绑定控件属性中的公共属性值的导航路径.这必须是一串由句点分隔的属性或字段名称,例如Tables [0] .DefaultView.[0] .Price在C#或Tables(0).DefaultView.(0)中.在Visual Basic中为Price."

据我了解,您不能直接绑定到表.
但是,您可以使用datatable或gridview列并将其绑定.
Eval (from documentation[^]) -
"The navigation path from the container object to the public property value to be placed in the bound control property. This must be a string of property or field names separated by periods, such as Tables[0].DefaultView.[0].Price in C# or Tables(0).DefaultView.(0).Price in Visual Basic."

As far as I understand, you cannot directly bind to a table.
However, you could use a datatable or gridview column and bind to it.


这篇关于#eval内部联接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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