上回总结了两篇关于控件的博客:
Asp.net 控件用法汇总-RadioButtonList、DropDownList、button、Checkbox...
Asp.net-不能在DropDownList中选择多个项
今天,把后续的再补充一些。
【Repeater】
Repeater控件,我把它叫做”控件中的for循环“。来个小例子:
<asp:Repeater ID="a_004" runat="server">
<div>
循环。。循环。。。
</div>
</asp:Repeater>
【Button】
设置Button的透明效果(炫炫哒):
<asp:Button ID="btnSavefeed" runat="server" Text="提交" Style="background-color:transparent;" /></asp:TextBox>
1、如何判断用html生成的radio控件是否选中。
所有html表单里面的值控件,提交后都是以键值key=value&key=value&……这样的形式提交给后台。(我觉得这是一个原理级别的语句)
radio也一样,会将选中的radio的value传回后台,后台用Request["radio的name"]取值就行了。如果有值说明选中了。(原理的应用)
如:
<inputtype="radio" value="1" name="rdo1"checked="checked"/>A
<inputtype="radio" value="2" name="rdo1"/>b
后台可以这样取值:Request["rdo1"]
值为:1
2、如何用js根据后台的值设置默认选中状态的单选按钮。
<html>
<head>
<title>初始化单选</title>
<script>
function initradio(rName,rValue){
var rObj = document.getElementsByName(rName);
for(var i = 0;i < rObj.length;i++){
if(rObj[i].value == rValue){
rObj[i].checked = 'checked';
}
}
}
</script>
</head>
<body>
<form action="#">
黑<input type="radio" name="tRadio" value="1">
色<input type="radio" name="tRadio" value="2">
头<input type="radio" name="tRadio" value="3">
发<input type="radio" name="tRadio" value="4">
</form>
<script>
initradio('tRadio',3);
</script>
</body>
</html>
分享来自: http://heisetoufa.iteye.com/blog/1137911
【DropDownList】
再推荐一篇总结的超简单超实用的博客:ASP.NET------DropDownList的使用方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~可爱的分割线~~~~~~~~~~~~~~~~~~~~~~~~~~~
再来总结一下常用的asp.net服务器控件分别与html元素的组对关系。
html : asp.net服务器控件
select : DropDownList
input : RadioButton/Checkbox/TextBox/Button
image : Image
table : Table
然后一句非常常用的代码:
runat="server"
它是用来设置控件及html元素是否与后台代码交互的。若html元素或者asp.net控件,设置了此属性,则在***.aspx.designer.cs中就会出现相应的id,表示它。如下图所示: