0

我有一个带有 Load 方法的 User 对象,该方法接受一个UserId参数并将用户数据加载到对象成员变量中。

现在我想做的是DetailsView使用 将这些数据加载到控件中ObjectDataSource,但我不知道如何。

首先,我不确定我是否已正确设置代码以将参数 (UserID) 传递给SelectMethod (cUser.Load). 其次,我不知道如何将这些数据加载到,DetailsView因为我实际上并没有从Load方法返回结果,我只是用数据加载对象......这是我的代码..

<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee"     Width="85%"
                    HorizontalAlign="Center"
                    Font-Bold="True" Font-Names="Verdana"
                    Font-Size="10pt" AutoGenerateColumns="False"
                    OnRowDataBound="GridView1_RowDataBound"
                    OnRowDeleting="GridView1_RowDeleting"
                    OnSelectedIndexChanged="IndexChanged" >
            <HeaderStyle BackColor="Black" ForeColor="White"
                   Font-Bold="True" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="yellow" ForeColor="blue" />
            <AlternatingRowStyle BackColor="#ffffff" />
                   <Columns>
                         <asp:TemplateField>
                       <ItemTemplate>
                           <asp:LinkButton ID="LinkButton2"
                             CommandArgument='<%# Eval("UserID") %>'
                             CommandName="Select" runat="server">
                             Select</asp:LinkButton>
                         </ItemTemplate>     
                         </asp:TemplateField>
                        <asp:BoundField DataField="UserID" Visible="false" />
                        <asp:BoundField DataField="FirstName" HeaderText="First Name"     />
                        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
                        <asp:TemplateField HeaderText="Delete?">
                         <ItemTemplate>
                           <asp:LinkButton ID="LinkButton1"
                             CommandArgument='<%# Eval("UserID") %>'
                             CommandName="Delete" runat="server">
                             Delete</asp:LinkButton>
                         </ItemTemplate>
                       </asp:TemplateField>
                    </Columns>
              </asp:GridView><br /><br />
              <asp:DetailsView runat="server" ID="dvUser"     DataSourceID="ObjectDataSource1" AutoGenerateRows="False" Width="85%"
                    HorizontalAlign="Center" DataKeyNames="UserID" >
                  <Fields>
                    <asp:BoundField DataField="UserID" Visible="false" />
                    <asp:BoundField DataField="FirstName" HeaderText="First Name" />
                    <asp:BoundField DataField="LastName" HeaderText="Last Name" />
                    <asp:BoundField DataField="UserName" HeaderText="User Name" />
                    <asp:BoundField DataField="Password" HeaderText="Password" />
                    <asp:BoundField DataField="Birthdate" HeaderText="Birthdate" />
                    <asp:BoundField DataField="Address" HeaderText="Address" />
                    <asp:BoundField DataField="Apt" HeaderText="Apt" />
                    <asp:BoundField DataField="City" HeaderText="City" />
                    <asp:BoundField DataField="Province" HeaderText="Province" />
                    <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
                    <asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" />
                    <asp:BoundField DataField="Email" HeaderText="Email" />
                    <asp:BoundField DataField="ynAdminUser" HeaderText="ynAdminUser" />
                    <asp:CommandField ShowDeleteButton="False" ShowEditButton="True"     ShowInsertButton="True" />
>
                </Fields>
            </asp:DetailsView>
                <asp:ObjectDataSource ID="ObjectDataSource1"
                    runat="server" SelectMethod="Load" TypeName="cUser">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="gvUsers" PropertyName="SelectedValue" Name="iUserID" Type="int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>

有没有办法做我想要实现的目标?如果是这样,你能举例说明吗?

非常感谢。谢谢

4

1 回答 1

0

您需要查看本教程以获取详细帮助....

使用带有详细信息 DetailView 的可选主 GridView 的主/详细信息

于 2009-11-16T07:03:28.387 回答