源码发在:http://www.tiantiansoft.com/bbs/dispbbs.asp?boardID=40&ID=134893
一、HTML标签的属性被视为已过时
<table align="center">:属性“align”被视为已过时
<td width="100">:属性“width”被视为已过时
解决:
<center>
<table width="300" border="1">
<tr>
<td align="left" style="width:100px; white-space:normal;">居左:长的长的长的长的长的长的长的长的长的</td>
<td style="width:100px;">居中</td>
<td align="right" style="width:100px;">居右</td>
</tr>
</table>
</center>
二、强类型DataSet
1、未能找到带参数的非泛型方法:user1/9/archives/2006/2470.html
2、未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值:user1/9/archives/2006/2471.html
三、数据绑定
1、使用Replace回车换行和显示HTML代码
<%# Convert.ToString(Eval("body")).Replace("<","〈").Replace(">","〉").Replace("\r","<br>") %>
2、用<%# %>同时绑定两个变量
例子:在cs文件里:public static int pg;
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "m_deal.aspx?t=1&pg=" + pg.ToString() + "&id=" + Eval("bid") %>'>回复</asp:HyperLink>
3、用三元运算符来绑定数据:条件?条件真的值:条件假的值
例子一:控制要显示的值
电子邮箱:<asp:Label ID="emailLabel" runat="server" Text='<%# Convert.ToInt32(Eval("isshowemail"))==0?"已设置隐藏":Convert.ToString(Eval("email","<a class=black href=mailto:{0}>{0}</a>")) %>'></asp:Label>
例子二:控制要不要隐藏
<asp:Label ID="answerLabel" runat="server" Text='<%# Bind("answer","管理员回复:{0}") %>' Visible='<%# Convert.ToString(Eval("atime"))==""?false:true %>'></asp:Label>
4、在FormView的模版里使用CheckBox:user1/9/archives/2006/2472.html
5、在FormView的模版里使用RadioButtonList方法:
FormView->ObjectDataSource1,在FormView的模板里的RadioButtonList->ObjectDataSource2,绑定:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatColumns="8" DataSourceID="ObjectDataSource2" DataTextField="tna" DataValueField="tid" RepeatDirection="Horizontal" SelectedValue='<%# Bind("tid") %>' DataSource='<%# Eval("tid") %>'></asp:RadioButtonList>
初始化RadioButtonList,默认选中第一项:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadioButtonList myrbl = new RadioButtonList();
myrbl = (RadioButtonList)FormView1.FindControl("RadioButtonList1");
if (myrbl != null)
{
myrbl.SelectedIndex = 0;
}
}
}
四、在提交更改前修改FormView控件里的数据
在FormView的InsertItemTemplate里:<asp:TextBox ID="btimeTextBox" runat="server" Text='<%# Bind("btime") %>'>
在提交数据前设置提交时间:
protected void InsertButton_Command(object sender, CommandEventArgs e)
{
//设置留言提交时间
TextBox mytb = new TextBox();
mytb = (TextBox)FormView1.FindControl("btimeTextBox");
if (mytb != null)
{
mytb.Text = System.DateTime.Now.ToString();
}
else
{
Response.Write("<script>alert('null');</script>");
}
}
因为在Page_Load里初始化,时间不对
五、在母版页里判断是否登录:user1/9/archives/2006/2473.html