English 中文(简体)
如何从雷贝雷亚特控制中获得数据
原标题:How to get data from controls in Repeater

我重复了项目模板:

<asp:Repeater ID="queryParametersRepeater" runat="server" 
  DataSourceID="queryParametersObjectDataSource">
  <ItemTemplate>
    <tr class="itemTemplate">
      <td class="labelTd" style="width: 300px;">
        <asp:HiddenField runat="server" Value= <%# Eval("ParameterType") %>  />
        Define <%# Eval("ParameterName") %> (type <%# Eval("ParameterType") %>)
      </td>                        
      <td class="valueTd">                            
        <asp:TextBox runat="server" Width="300px" Text= <%# Eval("ParameterName") %>  />
        <asp:CheckBox runat="server" Width="300px" />
      </td>
    </tr>
  </ItemTemplate>                
</asp:Repeater>

在j Query I的改动中,显示文本Box和chekBox的财产。 我如何能够从这些控制中获得数据?

I can t use FindControls() function, because I don t know id of my controls.

最佳回答

你们可以使用国际发展法,并设法控制这些价值观。 这方面的一个例子是:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //bind the data source
            RepeaterExample.DataSource = new List<KeyValuePair<int, string>>{
                new KeyValuePair<int,  string>(1, "Test1"), 
                new KeyValuePair<int,  string>(2, "Test2"), 
                new KeyValuePair<int,  string>(3, "Test3")
            };
            RepeaterExample.DataBind();
        }

    }

    protected void cmdSubmit_Click(object sender, EventArgs e)
    {
            //read the values and output them
            litResults.Text = "";
            foreach (RepeaterItem i in RepeaterExample.Items)
            {

                TextBox txtExample = (TextBox)i.FindControl("txtExample");
                if (txtExample != null)
                {
                    litResults.Text += txtExample.Text + "<br />";
                }
            }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Repeater ID="RepeaterExample" runat="server">
                    <HeaderTemplate>
                        test</HeaderTemplate>
                    <ItemTemplate>
                        <asp:TextBox ID="txtExample" runat="server" Text= <%#Eval("Value") %> ></asp:TextBox>
                    </ItemTemplate>
                </asp:Repeater><br />
                <asp:Button ID="cmdSubmit" runat="server" Text="Submit" OnClick="cmdSubmit_Click" />
                <br />
                <asp:Literal ID="litResults" runat="server"></asp:Literal>
            </div>
        </form>
    </body>
</html>
问题回答

Can you add a class to your controls? If so you could try with $(".givenClass").





相关问题
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!

热门标签