只要一页就可以了,用ACCESS数据库.
刚学.NET,不太懂这个,现在要用到,谢谢了!
刚学.NET,不太懂这个,现在要用到,谢谢了!
解决方案 »
- 问一下现在网页网络游戏都是使用什么语言和技术开发的?
- asp.net中sqlconnection和oledbconnection的问题
- 如何用C#实现点击主表的行然后从表显示详细数据
- 自定义控件的小问题!
- 如何让客户端运行时直接注册(在线等)
- datagrid在编辑状态怎么把一个列的值绑定或是处理后放到模板列的radiobuttonlist中?
- 如何把拷贝来的Web项目配置为可Debug
- 紧急,关于.net的B/S程序应用到企业局域网中的windows 2003+网络终端环境中的问题
- 关于ListBox的小问题?请帮帮忙
- QueryString 多参数如何分隔??
- table的select语句中,如何代替单字节?
- 请教高手,插入数据库记录的问题
private void gd_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string xs=e.CommandName ;
gd.EditItemIndex =-1;
gdBind();
} private void gd_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id=e.Item .Cells [primaryKeyCol].Text .Trim ();
string sqlAlone;
string r;
// string deptCode=((TextBox)e.Item .Cells [2].Controls [0]).Text .Trim ();
// string deptName=((TextBox)e.Item .Cells[3].Controls [0]).Text .Trim ();
// string leaderName=((TextBox)e.Item .Cells[4].Controls [0]).Text .Trim ();
// string leaderCode=((TextBox)e.Item .Cells [5].Controls [0]).Text .Trim ();
//
//sql="update department set department_code='"+deptCode+"',department_name='"+deptName+"',"+
//"department_leader='"+leaderName+"',department_leadercode='"+leaderCode+"' where department_id="+id;
//
sql="update "+tablename+" set ";
for(int i=1;i<myDt.Rows.Count;i++)
{
//判断非空
string name;
if(myDt.Rows [i]["datanull"].ToString ()=="false")
{
name=((TextBox)e.Item .Cells [i+1].Controls [0]).Text.Trim ().Replace ("'","");
if(name=="")
{
Response.Write ("<script language=javascript>alert('"+myDt.Rows [i]["headtext"].ToString ().Replace ("'","")+"不能为空!')</script>");
return;
} }
// 判断重复
if(myDt.Rows [i]["dataalone"].ToString ()=="true")
{
sqlAlone="select count (*) from "+tablename+" where "+myDt.Rows [i]["dataname"].ToString ()+"='"+
((TextBox)e.Item .Cells [i+1].Controls [0]).Text.Trim ().Replace ("'","")+"' and "+primaryKey+"<>"+id;
r=dataClass.ExecuteSqlResult (sqlAlone,exp);
if(r!="0")
{
Response.Write ("<script language=javascript>alert('"+myDt.Rows [i]["headtext"].ToString ()+"重复!')</script>");
return;
} }
if(i!=myDt.Rows.Count -1)
{
if(myDt.Rows[i]["datatype"].ToString()=="text")
//在datagrid中 row 为 i+1
sql=sql+myDt.Rows[i]["dataname"].ToString()+"='"+((TextBox)e.Item .Cells [i+1].Controls [0]).Text.Trim ().Replace ("'","")+"',";
else
sql=sql+myDt.Rows[i]["dataname"].ToString()+"="+((TextBox)e.Item .Cells [i+1].Controls [0]).Text.Trim ().Replace ("'","")+",";
}
else
{
if(myDt.Rows[i]["datatype"].ToString()=="text")
sql=sql+myDt.Rows[i]["dataname"].ToString()+"='"+((TextBox)e.Item .Cells [i+1].Controls [0]).Text.Trim ().Replace ("'","")+"'";
else
sql=sql+myDt.Rows[i]["dataname"].ToString()+"="+((TextBox)e.Item .Cells [i+1].Controls [0]).Text.Trim ().Replace ("'","");
}
}
sql=sql+" where "+primaryKey+"="+id;
dataClass.ExecuteSqlNoResult (sql,exp);
gd.EditItemIndex =-1;
gdBind();
} private void gd_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
gd.EditItemIndex =(int)e.Item .ItemIndex ;
gdBind();
} private void gd_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
gd.CurrentPageIndex =e.NewPageIndex ;
currentPage=gd.CurrentPageIndex ;
gdBind();
} private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("../manage/someContentAdd.aspx?xmlconfig="+xmlConfig);
} private void ImageButton2_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
int[] state=new int[20];
for(int i=0;i<gd.Items.Count;i++)
{
state[i]=0;
DataGridItem delDataGridItem=gd.Items[i];
CheckBox delCheckBox=(CheckBox)delDataGridItem.FindControl("CheckBox"); if(delCheckBox.Checked)
{
state[i]=1;
}
} gdBind();
for(int i=0;i<gd.Items.Count;i++)
{
DataGridItem delDataGridItem=gd.Items[i];
string contentId=delDataGridItem.Cells [primaryKeyCol].Text; if(state[i]==1)
{
string delSql="delete from "+tablename+" where "+primaryKey+"="+contentId;
dataClass.ExecuteSqlNoResult (delSql,exp);
}
}
Response.Redirect("someInfo.aspx?xmlconfig="+xmlConfig+"¤tpage="+currentPage);
} private void gd_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
<Script Language="VB" Runat="Server">
Sub BindList()
Dim strSQL As String = "Select Top 5 d_bookname As 抎靡,d_author As 釬氪,profession_no As 巠蚚蚳珛,d_id From t_source"
myDataGrid.DataSource = CreateDataSet(strSQL, "ssyyrr.mdb", "諒悝統蕉抎")
myDataGrid.DataMember="諒悝統蕉抎"
myDataGrid.DataBind()
End SubSub Page_Load(sender As Object, e As Eventargs)
If Not IsPostBack Then BindList()
End Sub
Sub DataGrid_EditCommand(sender As Object, e As DataGridCommandEventArgs)
myDataGrid.EditItemIndex = e.Item.ItemIndex
BindList()
End SubSub DataGrid_CancelCommand(sender As Object, e As DataGridCommandEventArgs)
myDataGrid.EditItemIndex = -1
BindList()
End SubSub DataGrid_UpdateCommand(sender As Object, e As DataGridCommandEventArgs)
Dim d_bookname As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim d_author As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim profession_no As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim strSQL As String
strSQL = "Update t_source Set d_bookname='" & d_bookname & "', d_author='" & d_author & "', profession_no='" & profession_no & "' Where " & myDataGrid.DataKeyField & "=" & myDataGrid.DataKeys(e.Item.ItemIndex)
Dim objConn As New OleDbConnection()
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Ssyyrr.mdb")
objConn.Open()
Dim objCmd As New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery
myDataGrid.EditItemIndex = -1
BindList()
End Sub
</Script><Html>
<Body BgColor="#ffffcc">
<H1 Align="Center">諒悝統蕉抎奪燴炵苀</H1>
<Form Runat="Server">
<Asp:DataGrid Runat="Server" Id="myDataGrid" AutoGenerateColumns="False" DataKeyField="d_id" HorizontalAlign="Center" Width="700" OnEditCommand="DataGrid_EditCommand" OnUpdateCommand="DataGrid_UpdateCommand" OnCancelCommand="DataGrid_CancelCommand">
<HeaderStyle HorizontalAlign="Center" BackColor="#66CCFF" ForeColor="White" />
<ItemStyle BackColor="Moccasin" />
<Columns>
<Asp:TemplateColumn HeaderText="晤瘍">
<ItemTemplate>
<%# Container.DataItem("d_id") %>
</ItemTemplate>
<EditItemTemplate>
<%# Container.DataItem("d_id") %>
</EditItemTemplate>
</Asp:TemplateColumn>
<Asp:BoundColumn HeaderText="抎靡" DataField="抎靡" />
<Asp:BoundColumn HeaderText="釬氪" DataField="釬氪" />
<Asp:BoundColumn HeaderText="巠蚚蚳珛" DataField="巠蚚蚳珛" />
<Asp:EditCommandColumn EditText="晤憮" CancelText="秏" UpdateText="載陔" HeaderText="髡夔" ItemStyle-HorizontalAlign="Center" />
</Columns>
</Asp:DataGrid>
</Form>
</Body>
</Html>