Dim fltext as textbox=e.Item.Cells(1).Controls(0)
Dim flname as string=fltext.Text
我获得的数据还是没改之前的呀。
就是说我原来的是username为liming
可我改为1111后。我取的直还是liming
怎么回事呀
Dim flname as string=fltext.Text
我获得的数据还是没改之前的呀。
就是说我原来的是username为liming
可我改为1111后。我取的直还是liming
怎么回事呀
解决方案 »
- My97DatePicker时间控件在本机能用,放到服务器上没反应。
- 网站中关于从Excel文件实现批量导入数据的实现方法,怎么样可以实现?
- 哪有asp.net 英文版的电子书下啊
- 问一个郁闷一整天的问题
- c#中如何完成对Treeview控件中选择框CheckBox的全选处理
- 网页很长,如何滚动到本页后部某一位置,(锚定处?)
- 关于“后退”按钮的问题,为什么在IE中,有些值不能取到?
- 我客户端有个txt文件,数据库里导出来的,我想把他到回到服务器的sqlserver数据库,并覆盖已有数据,该如何实现呀
- 把IP地址的最后那部分显示为*
- 有实现asp.net 链接数据库实现字体跑马灯效果的代码吗?
- 一个asp.net(vb)RadioButtonList连接数据库更新问题!
- 我用DrawString绘制的字不清楚,不知道怎摸解决:(
sub fenlei_update(Sender as Object,e as DataGridCommandEventArgs)
Dim fltext as textbox=e.Item.Cells(1).Controls(0)
Dim flname as string=fltext.Text
Dim cmd as OleDbCommand
Dim sql,bianhao,strConn as string
dim mycon as OleDbConnection
bianhao=fenlei.DataKeys(e.Item.ItemIndex)
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.MapPath("../data/wsl.mdb")
mycon=new OleDbConnection(strConn)
sql="update admin set userName='"+flname+"' where ID="+bianhao+"" response.write (sql)
response.end
myCon.open()
Cmd=new OleDbCommand(sql,myCon)
Cmd.ExecuteNonQuery()
myCon.close()
fenlei.EditItemIndex=-1
fenlei.DataBind()end sub
<edititemtemplate>
</edititemtemplate>
有
Dim fltext as textbox=e.Item.Cells(1).Controls(1)
<asp:datagrid ID="fenlei" AllowPaging="true" PageSize="10"
PagerStyle-HorizontalAlign="right" PagerStyle-Mode="NumericPages" HeaderStyle-BackColor="#0099FF"
HeaderStyle-ForeColor="#FFFFFF" BorderColor="#000000" AutoGenerateColumns="false" DataKeyField="ID" runat="server"
OnEditCommand="fenlei_edit" OnCancelCommand="fenlei_cancel" OnUpdateCommand="fenlei_update"
>
<columns>
<asp:BoundColumn DataField="ID" HeaderText="用户编号" ReadOnly="true"/>
<asp:boundcolumn DataField="userName" HeaderText="用户名"/>
<asp:boundcolumn DataField="password" HeaderText="密 码"/>
<asp:editcommandcolumn
EditText="编辑"
CancelText="取消"
UpdateText="更新"
HeaderText="命令"/>
</columns>
</asp:datagrid>
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace localhost.datagrid
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DataGrid dg1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
databind();
}
}
private void databind()
{
SqlConnection conn;
conn=new SqlConnection("Data Source=localhost;Database=test;User Id=sa;Pwd=sa");
conn.Open();
SqlDataAdapter da=new SqlDataAdapter("select * from tadagrid1 order by id asc",conn);
DataSet ds=new DataSet();
try
{
da.Fill(ds,"table1");
dg1.DataSource=ds.Tables["table1"];
dg1.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
conn.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dg1.SelectedIndexChanged += new System.EventHandler(this.dg1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void dg1_SelectedIndexChanged(object sender, System.EventArgs e)
{
} private void Button3_Click(object sender, System.EventArgs e)
{
shop shopw=getshop();
(new data()).add(shopw);//建立新的一行. databind();//刷新
}
private shop getshop()
{
shop shopn=new shop();
shopn.name1="";
shopn.text1="";
return shopn;
} private void Button2_Click(object sender, System.EventArgs e)
{
update();
databind();//刷新
}
private void update()
{ //string str1="";
//string str2="";
for(int i=0;i<dg1.Items.Count;i++)//dg1.Items.Count的用法
{
//DataGridItem dgitem=e.item;
TextBox text2=(TextBox) dg1.Items[i].FindControl("text1");
Label l2=(Label) dg1.Items[i].FindControl("label1");
Label l3=(Label) dg1.Items[i].FindControl("Label4");
// int ids=Convert.ToInt32( l3.Text);
// str1+=l2.Text; // shop shopn=new shop();
//shopn.name1==text2.Text;
//shopn.text1==l2.Text;
shop shope=new shop(text2.Text.Trim(),l2.Text,Convert.ToInt32( l3.Text));
shope.save();// }
} private void Button1_Click(object sender, System.EventArgs e)
{
//Label2.Text="terwtyy";
delete1();
databind();//刷新
}
private void delete1()
{
string str1=string.Empty;
for(int i=0;i<dg1.Items.Count;i++)
{
CheckBox ch1=(CheckBox) dg1.Items[i].FindControl("chk");
Label l3=(Label) dg1.Items[i].FindControl("Label4");
if(ch1.Checked)
{
str1+="f";
(new data()).delete1(Convert.ToInt32( l3.Text)); //删除
}
}
Label2.Text=str1;
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="css/css.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<script language="javascript">
function click1()
{
alert("error !!!!");
} </script>
<FONT face="宋体">
<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False" CellPadding="3" BackColor="#DEBA84"
BorderWidth="1px" CellSpacing="2" BorderStyle="None" BorderColor="#DEBA84">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="button">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<button id="button1" onclick="click1()" type="button" runat="server" value="Button">
</button>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="remve">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chk" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="name1">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="text1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"name1")%>' >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="text1">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<asp:Label ID="label1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"text1")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ID">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<asp:Label ID="Label4" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"id")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
<asp:Label id=Label2 style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 232px" runat="server" Width="168px">Label</asp:Label>
<asp:button id=Button2 style="Z-INDEX: 102; LEFT: 88px; POSITION: absolute; TOP: 264px" runat="server" Text="保存"></asp:button>
<asp:button id=Button3 style="Z-INDEX: 103; LEFT: 208px; POSITION: absolute; TOP: 272px" runat="server" Text="新建"></asp:button>
<asp:button id="Button1" runat="server" Text="选取" style="Z-INDEX: 104; LEFT: 24px; POSITION: absolute; TOP: 264px"></asp:button>
</FONT>
</form>
</body>
</HTML>
if(!IsPostBack)
{
databind();
}
不然它会在每一个点击后重新绑定,所以你取的值老是原先的值.