在不同条件下为asp datagrid中的列分配不同的字段 [英] assigning differnt field to a column in asp datagrid in different condition

查看:93
本文介绍了在不同条件下为asp datagrid中的列分配不同的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个asp数据网格,我从实体集合中填充数据。

我的实体包含BusTicketNo ,TrainTicketNo和PassagengerName。并且mygrid有标题为

TICKETNo和PAXNAME。在我的用户将选择火车旅程或巴士旅程的地方有Dropdown。如果它选择火车,那么我的TICKETNO列应该映射到TrainTicketNo字段或BusTicketNo字段。



我的网格模板如下所示



Hi All,

I have a asp datagrid, where I am populating data from an entity collection.
My entity contains BusTicketNo, TrainTicketNo and PassagengerName. And mygrid has header as
TICKETNo and PAXNAME. and there is Dropdown in my from where the user will select the it ia a train journey or bus journey.If it selects the train then my TICKETNO column should be mapped to the TrainTicketNo field or else BusTicketNo field.

my grid templates are as shown below

<asp:TemplateField HeaderText="Ticke No" HeaderStyle-Width="10%">
    <ItemTemplate>
        <asp:TextBox ID="txtTicketNo" runat="server"

        Width="129px"  Text='<%#Eval("BusTicketNo")%>'>
        </asp:TextBox>
    </ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />

</asp:TemplateField>
<asp:TemplateField HeaderText="Passenger Name" HeaderStyle-HorizontalAlign="Center">
    <ItemTemplate>
            <asp:TextBox ID="paxName" runat="server"

            Width="129px"  Text='<%#Eval("PassengerName")%>'></asp:TextBox>
    </ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="15%" />
</asp:TemplateField>







假设用户从下拉列表中选择火车旅程我如何将trainticketno字段绑定到txtTicketNo模板。



谢谢

PP




Suppose the user selects the train journey from the drop down how can I bind the trainticketno field to the txtTicketNo template.

Thanks
PP

推荐答案

我得到了sol我自己。

通过使用grid的数据行绑定事件从每一行获取dataitem对象。然后获取该列,意味着获取控件文本框或标签或下拉列表然后将texe属性绑定到该数据项对象属性。



首先将数据项强制转换为对象。然后使用object属性来控制该值。
I got the solution by myself.
the dataitem object is to be fetched from each row by using the data row bound event of the grid.And then get that column , means get the control text box or label or drop down list and then bind the texe property to that data item object property.

first type cast the data item to the the object. and then use the object property to that controls value.


这篇关于在不同条件下为asp datagrid中的列分配不同的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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