|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于new隐藏成员的作用,往往是出于使用了一个第三方类库,而你又无法获得这个类库的源代码,当你继承这个类库的某个类时,你需要重新实现其中的一个方法,而又需要与父类中的函数使用同样的函数,这是就需要在自定义的子类中把那个同名函数(或成员)加上new标记,从而隐藏父类中同名的成员。以下为完成在GridView选中,编纂,作废,删除数据功效的全体代码,列位只需复制粘贴到vs中便可运转。
前台完成代码:
<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>
背景完成代码:
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();
}
}
以上内容来历于互联网,原作者已没法得知,在此感激原作者的忘我贡献。java的设计机制:首先产生一个中间码,第二部编译为本地(机器)码。这个机制有很大的缺点。 |
|