English 中文(简体)
使用重复器控件作为嵌套网格视图的命令参数。
原标题:Using Repeater Control as a command parameter for a nested gridview

我有一个包含嵌套网格视图的重复器。现在我需要能够检索重复器中标签中绑定的值,并将其用作网格视图的输入参数。

这里有一些代码,希望能让你更清楚我想要做什么。

enter code here

  <asp:Repeater ID="Repeater1" runat="server" DataSourceID="RepeaterDS"  OnItemDataBound="Repeater1_SendRollNumber">
                <HeaderTemplate>
                </HeaderTemplate>
                <ItemTemplate>
                    <table style="width: 615px;" id="Table1">
                        <tr>
                            <td>
                                <b>Roll #:</b>
                                <asp:Label runat="server" ID="RollIDLabel" Text= <%# Eval("RollID") %>  />
                                <asp:Label runat="server" ID="RollIDLabelCode" Text= <%# Eval("RollID") %>  Visible="false" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Address:</b>
                                <asp:Label runat="server" ID="AddressLabel" Text= <%# Eval("Address") %>  />
                    </table>
                    <asp:Label ID="Label1" runat="server"><b>Parties:</b></asp:Label>
                    <asp:GridView ID="GridView3" runat="server" BackColor="White" BorderColor="#DEDFDE"
                        BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"
                        AllowPaging="True" Width="620px" DataSourceID="AssessmentDetailsFromRollIDDS"
                        EmptyDataText="None Associated" AutoGenerateColumns="False" ShowFooter="true">
                                                        <asp:TemplateField HeaderText="Property Assessment" HeaderStyle-Font-Bold="true"
                                FooterStyle-BackColor="White">
                                <ItemTemplate>
                                    <asp:Label ID="PropAssessType" runat="server" Width="90%" Text= <%# Eval("PropertyAssessmentType") %> ></asp:Label>
                                    <asp:Label ID="PropAssessDsc" runat="server" Text= <%# Eval("PropertyAssessmentDesc") %> ></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                </FooterTemplate>
                            </asp:TemplateField>

                        <RowStyle BackColor="#F7F7DE" />
                        <FooterStyle BackColor="#CCCC99" />
                        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#3E4E4E" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                </ItemTemplate>
            </asp:Repeater>

    <asp:ObjectDataSource ID="RepeaterDS" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetRollNumberbyAppealID" TypeName="BusinessLayer.BSO.Roll_AssessmentDetailsBSO">
        <SelectParameters>
            <asp:QueryStringParameter Name="AppealID" QueryStringField="appealID" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <asp:ObjectDataSource ID="AssessmentDetailsFromRollIDDS" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetAssessDetailsFromRollID" OnSelecting="AssessmentDetailsFromRollIDDS_Selecting" TypeName="BusinessLayer.BSO.Assessment_DetailsBSO">
        <SelectParameters>
           <asp:ControlParameter Name="RollID" ControlID="RollIDLabelCode" Type="String" /> 
        </SelectParameters>
    </asp:ObjectDataSource>

我已经尝试尽可能地减少代码,同时保留问题的核心。因此,我基本上希望位于重复器中的标签控件RollIDLabelCode也成为我的网格视图的输入。问题在于,我一直收到诸如找不到控件RollIDLabelCode之类的错误。我听说有一个错误需要指定所有命名容器,但我已经尝试过没有成功。

我尝试过的另一种方法是在代码后台完成这项任务。

enter code here


    public void Repeater1_OnItemDataBound(Object Sender, RepeaterItemEventArgs e)
    {
                  // Execute the following logic for Items and Alternating Items.
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            string  test = ((Label)e.Item.FindControl("RollIDLabel")).Text;
        }
    }

    public void AssessmentDetailsFromRollIDDS_OnSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {

        e.InputParameters["RollID"] = "Need the Info here";
    }

这些功能在数据重复器和对象数据源选择函数上被调用。这些可以分别很好地工作。我只需要知道如何将Repeater1_OnItemDataBound函数中的字符串测试信息获取到OnSelecting函数中的e.InputParameters ["RollID"]中。

希望有人知道如何做到这一点。我是.NET编程的新手。我感激任何帮助。

谢谢!

问题回答

RollIDLabelCode标签被设置为visible=false,这意味着它在呈现时将不存在,因此尝试访问该值将不可能。您需要使用一个不可见但在呈现时存在的不同控件。例如,GridView具有数据键存在于控件中但不呈现,它用于检索行的键值以检索更多数据。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签