|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
以前很热炒跨平台,主要是由于硅谷挑战微软霸主地位的热情,但是冷静下来后,跨平台往往不是那么一回事。假设你有个软件,所谓的跨平台,你只需要为第二个平台上重新编译一次就行了,这样很难么?先不说了,间接上代码:
更多GridView利用技能,请下载本站的GridView利用技能
背景次要代码:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;
publicpartialclass_Default:System.Web.UI.Page
{
SqlConnectionsqlcon;
SqlCommandsqlcom;
stringstrCon="DataSource=(local);Database=数据库名;Uid=帐号;Pwd=暗码";
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{
bind();
}
}
protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse)
{
GridView1.EditIndex=e.NewEditIndex;
bind();
}
//删除
protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse)
{
stringsqlstr="deletefrom表whereid="+GridView1.DataKeys[e.RowIndex].Value.ToString()+"";
sqlcon=newSqlConnection(strCon);
sqlcom=newSqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();
}
//更新
protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse)
{
sqlcon=newSqlConnection(strCon);
stringsqlstr="update表set字段1="
+((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim()+",字段2="
+((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim()+",字段3="
+((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim()+"whereid="
+GridView1.DataKeys[e.RowIndex].Value.ToString()+"";
sqlcom=newSqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex=-1;
bind();
}
//作废
protectedvoidGridView1_RowCancelingEdit(objectsender,GridViewCancelEditEventArgse)
{
GridView1.EditIndex=-1;
bind();
}
//绑定
publicvoidbind()
{
stringsqlstr="select*from表";
sqlcon=newSqlConnection(strCon);
SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);
DataSetmyds=newDataSet();
sqlcon.Open();
myda.Fill(myds,"表");
GridView1.DataSource=myds;
GridView1.DataKeyNames=newstring[]{"id"};//主键
GridView1.DataBind();
sqlcon.Close();
}
}
前台次要代码:......
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"CellPadding="4"
ForeColor="#333333"GridLines="None"OnRowDeleting="GridView1_RowDeleting"OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"OnRowCancelingEdit="GridView1_RowCancelingEdit">
<FooterStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<Columns>
<asp:BoundFieldDataField="身份证号码"HeaderText="用户ID"ReadOnly="True"/>
<asp:BoundFieldDataField="姓名"HeaderText="用户姓名"/>
<asp:BoundFieldDataField="员工性别"HeaderText="性别"/>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"/>
<asp:CommandFieldHeaderText="选择"ShowSelectButton="True"/>
<asp:CommandFieldHeaderText="编纂"ShowEditButton="True"/>
<asp:CommandFieldHeaderText="删除"ShowDeleteButton="True"/>
</Columns>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>
java的设计机制:首先产生一个中间码,第二部编译为本地(机器)码。这个机制有很大的缺点。 |
|