|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果需要重新编写代码,几乎任何一门计算机语言都可以跨平台了,还用得着Java嘛,而且像PHP/C#等语言不需要修改代码都可以跨Windows/Linux。</p>最终效果:
html代码
<tablealign="center"bgcolor="#c0de98"border="0"cellpadding="0"cellspacing="1"width="99%">
<tr>
<thcolspan="2">
GridView演示</th>
</tr>
<tr>
<tdcolspan="2"style="width:100%;">
<asp:GridViewID="GridView"runat="server"Width="100%"AutoGenerateColumns="False"AllowPaging="True"OnPageIndexChanging="GridView_PageIndexChanging"PageSize="12"OnRowDeleting="GridView_RowDeleting"OnRowDataBound="GridView_RowDataBound">
<Columns>
<asp:BoundFieldDataField="UserID"HeaderText="UserID"ReadOnly="True"/>
<asp:BoundFieldDataField="C_Name"HeaderText="中文名字"ReadOnly="True"/>
<asp:BoundFieldDataField="E_Name"HeaderText="英文名字"ReadOnly="True"/>
<asp:BoundFieldDataField="QQ"HeaderText="QQ帐号"/>
<asp:CommandFieldHeaderText="删除"ShowDeleteButton="True"/>
</Columns>
<RowStyleHorizontalAlign="Center"/>
<PagerStyleHorizontalAlign="Right"/>
</asp:GridView>
</td>
</tr>
</table>C#代码
usingSystem;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
publicpartialclassDemo11:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(Page.IsPostBack==false)
{
BindData();
}
}
publicvoidBindData()
{
stringstrSql="selectUserID,C_Name,E_Name,QQfromDemo_User";
DataTabledt=SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING,CommandType.Text,strSql,null).Tables[0];
GridView.DataSource=dt;
GridView.DataKeyNames=newstring[]{"UserID"};//主键
GridView.DataBind();
}
protectedvoidGridView_PageIndexChanging(objectsender,GridViewPageEventArgse)
{
GridView.PageIndex=e.NewPageIndex;
BindData();
}
protectedvoidGridView_RowDeleting(objectsender,GridViewDeleteEventArgse)
{
intUserID=(int)GridView.DataKeys[e.RowIndex].Value;
stringstrSql="DeleteDemo_UserwhereUserID=@UserID";
SqlParameter[]para={
newSqlParameter("@UserID",UserID),
};
SqlHelper.ExecuteNonQuery(SqlHelper.CONN_STRING,CommandType.Text,strSql,para);
BindData();
}
protectedvoidGridView_RowDataBound(objectsender,GridViewRowEventArgse)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
if(e.Row.RowState==DataControlRowState.Normale.Row.RowState==DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick","javascript:returnconfirm("你确认要删除:""+e.Row.Cells[1].Text+""吗?")");
}
}
}
}我认为,可以通过更加简单的首次编译,而增加第二次编译的负担,来提高java的运行效率。只是将java源代码进行简单的等价转换,而不假设编译成某种虚拟机器的目标格式,而由本地编译器针对性的二次编译。 |
|