中继器标记:
<asp:Repeater ID="stat_Rptr" runat="server">
<ItemTemplate>
<asp:CheckBox ID="IsSelected_ChkBx" runat="server" Text='<%# Eval("Item") %>' />
<asp:TextBox ID="Value_TxtBx" runat="server"></asp:TextBox>
<asp:HiddenField ID="ID_HdnFld" runat="server" Value='<%# Eval("ID") %>' />
</ItemTemplate>
<SeparatorTemplate>
<br></br>
</SeparatorTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateStatRptr();
}
}
private void PopulateStatRptr()
{
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
string _connString = "Data Source=localhost\\SqlExpress;Initial Catalog=MyDb;Integrated Security=True";
conn = new SqlConnection(ConString);
comm = new SqlCommand("SELECT ID, Item FROM Stats", conn);
try
{
conn.Open();
reader = comm.ExecuteReader();
stat_Rptr.DataSource = reader; …Run Code Online (Sandbox Code Playgroud) 我已经在VS2008上投入了WebForms ASP.NET 3.5项目.该解决方案有5个项目,因此不会太大.让我烦恼的一件事是从F5到实际网页需要花多长时间我可以做些什么(好15-20秒).我所使用的盒子是相对较新的 - 其他一切都感觉非常活泼.
我可以做些什么来加快这个过程?
我有一个简单的aspx页面,其中有一个表单和一个输入字段,如下所示.
//basket.aspx
<input type="text" id="TotalPrice" runat="server" name="TotalPrice" value="100" />
<asp:button ID="btnBuy" runat="server" Text="make payment" PostBackUrl="~/payment" />
</form>
Run Code Online (Sandbox Code Playgroud)
这是pay.aspx,但是当我在payment.aspx的页面加载中调试Request.Form时,我无法达到像Request.Form ["TotalPrice"]这样的TotalPrice值.发布到另一个aspx页面获取值的最佳方法是什么?为什么我尝试的方式不起作用?
public class SecretNumber
{
//Construktor
public SecretNumber()
{
Initialize();
_previousGuesses = new List<int>();
}
//Constant
public const int MaxNumberOfGuesses = 7;
//Field
private int _number;
private List<int> _previousGuesses;
//Property
public bool CanMakeGuess
{
get;
}
public int Count
{
get;
}
public int? Number
{
public get;
}
//Lite oklart hur man ska göra när fälten är autoimplementerade
public Outcome Outcome1
{
get
{
return Outcome1;
}
private set
{
Outcome1 = value;
}
}
public ReadOnlyCollection<int> PreviousGuesses
{
get; …Run Code Online (Sandbox Code Playgroud) 所以,我在一个页面上有一个登录框和一个注册框.两者都有RequiredField验证器.现在,当我点击登录或注册时,注册和登录的字段都会得到验证.
但是,我想要它,如果点击注册,只有注册字段得到验证,如果点击登录字段,则验证.
你能帮帮我吗?
非常感谢!
嗨,我对asp.net中的按钮点击有一个疑问,我已经在.aspx页面中放置了按钮控件和OnClick事件以及其他一些控件(按钮,文本框).当我运行页面时,按钮显示在浏览器的页面源中,就像这里一样,它不显示onclick事件,然后页面如何调用服务器端的按钮单击,服务器端如何识别哪个按钮导致提交,以及此页面如何移动到服务器端.
我有一个列表对象
List<Documents>
Run Code Online (Sandbox Code Playgroud)
,在里面,我有另一个帐户列表.
List<Accounts>
Run Code Online (Sandbox Code Playgroud)
从我的代码隐藏我将List连接到转发器控件
rptDocumentListings.DataSource = List<Documents>;
rptDocumentListings.DataBind();
Run Code Online (Sandbox Code Playgroud)
当转发器循环遍历List中的每个项目时,我希望它也通过每个嵌套帐户列表循环,然后使用
标签呈现.这是我到目前为止所尝试的:
//in the dataRepeater
<%# parseAccountNumbers(Eval("Accounts"))%>
//method in codebehind
public string parseAccountNumbers(List<Account> accounts)
{
string allAccounts = string.Empty;
foreach (var item in accounts)
{
allAccounts += string.Format("{0}<br />", item.AccountNumber);
}
return allAccounts;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是'无法从'对象'转换为'System.Collections.List'有人可以指出我正确的方向吗?提前致谢.
我正在使用C#ASP.net,并且相对较新,需要在下面完成.
在我的VS2010 Web应用程序项目中,我有default.aspx,form1.aspx,button1和form2.aspx.
1 - 我想将form1设置为我的主页(当我运行应用程序时打开的第一个页面)2 - 当我单击form1上的按钮时打开form2
另外,请你推荐一本涵盖上述内容的好书吗?
谢谢Jay
在ASP.NET MVC中,在[HttpPost]方法上,MVC运行时将根据字段名称自动映射前端表单字段中的数据并将其传输到视图模型中.
如何在ASP.NET WebForm中完成相同的操作?
例如,我有一个名为Person的对象,具有FirstName和LastName属性.
我有一个WebForm页面,文本框控件分别带有FirstName和LastName.
当在表单上按提交时,有没有办法在代码隐藏的Button_Click事件中自动将FirstName和LastName绑定到Person对象?
asp.net-mvc webforms dry single-responsibility-principle model-binding
快速问题 - 如果webform中的文本字段没有自动设置表单的焦点,即你必须在键盘弹出之前按下该字段 - 我是否正确认为该字段无法编辑呢?
换句话说 - 我不能通过向其中注入javascript来为textField设置文本,除非它在加载网站时得到关注吗?
注意:我不是在这里讨论设置文本或占位符:-)
干杯
webforms ×10
asp.net ×8
c# ×4
.net ×2
asp.net-mvc ×1
dry ×1
ios ×1
javascript ×1
performance ×1
post ×1
single-responsibility-principle ×1
uitextfield ×1
validation ×1