protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string DataType = " server=localhost;Initial Catalog=Domain;user id=sa;password=123456 ";
string selectSQL = " Select * From DomainList Where ID=" + Request.QueryString["ID"] + " ";
SqlConnection Conn = new SqlConnection(DataType);
SqlCommand selectCmd = new SqlCommand(selectSQL, Conn);
try
{
Conn.Open();
FormView1.DataSource = selectCmd.ExecuteReader();
FormView1.DataBind();
}
catch (Exception err)
{
lblMessage.Text = err.Message;
}
finally
{
Conn.Close();
}
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
string DataType = " server=localhost;Initial Catalog=Domain;user id=sa;password=123456 ";
string updateSQL = " update DomainList set DomainName='" + DomainName.Text + "',Scope='"+ Scope.Text +"',EditDate='" + DateTime.Now.ToShortDateString() + "' Where ID='" + Request.QueryString["ID"] + "' ";
SqlConnection Conn = new SqlConnection(DataType);
SqlCommand UpdateCmd = new SqlCommand(updateSQL, Conn);
int Added = 0;
try
{
Conn.Open();
Added = UpdateCmd.ExecuteNonQuery();
if (Added > 0)
{
Response.Write("<script>alert('修改成功!');location.href='Default.aspx';</script>");
}
else
{
Response.Write("<script>alert('出现错误!修改失败!');history.back(-1);</script>");
}
}
catch (Exception err)
{
lblMessage.Text = err.Message;
}
finally
{
Conn.Close();
}
}
}<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
<table style="width: 569px">
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
修改名称</td>
</tr>
<tr>
<td style="width: 100px">
域名:</td>
<td style="width: 100px">
<asp:TextBox ID="DomainName" runat="server" Text='<%# Bind("DomainName") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DomainName"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:Button ID="btnAdd" runat="server" Text="提 交" OnClick="btnAdd_Click"/><input id="Reset1" type="reset" value="重 填" /></td>
</tr>
<tr>
<td style="width: 100px">
范围:</td>
<td style="width: 100px">
<asp:RadioButtonList ID="Scope" runat="server" Text='<%# Bind("Scope") %>'>
<asp:ListItem Value="World">国际</asp:ListItem>
<asp:ListItem Value="China">国内</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="Scope"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator></td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:Label ID="lblMessage" runat="server"></asp:Label></div>
</form>
</body>
{
if (!Page.IsPostBack)
{
string DataType = " server=localhost;Initial Catalog=Domain;user id=sa;password=123456 ";
string selectSQL = " Select * From DomainList Where ID=" + Request.QueryString["ID"] + " ";
SqlConnection Conn = new SqlConnection(DataType);
SqlCommand selectCmd = new SqlCommand(selectSQL, Conn);
try
{
Conn.Open();
FormView1.DataSource = selectCmd.ExecuteReader();
FormView1.DataBind();
}
catch (Exception err)
{
lblMessage.Text = err.Message;
}
finally
{
Conn.Close();
}
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
string DataType = " server=localhost;Initial Catalog=Domain;user id=sa;password=123456 ";
string updateSQL = " update DomainList set DomainName='" + DomainName.Text + "',Scope='"+ Scope.Text +"',EditDate='" + DateTime.Now.ToShortDateString() + "' Where ID='" + Request.QueryString["ID"] + "' ";
SqlConnection Conn = new SqlConnection(DataType);
SqlCommand UpdateCmd = new SqlCommand(updateSQL, Conn);
int Added = 0;
try
{
Conn.Open();
Added = UpdateCmd.ExecuteNonQuery();
if (Added > 0)
{
Response.Write("<script>alert('修改成功!');location.href='Default.aspx';</script>");
}
else
{
Response.Write("<script>alert('出现错误!修改失败!');history.back(-1);</script>");
}
}
catch (Exception err)
{
lblMessage.Text = err.Message;
}
finally
{
Conn.Close();
}
}
}<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
<table style="width: 569px">
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
修改名称</td>
</tr>
<tr>
<td style="width: 100px">
域名:</td>
<td style="width: 100px">
<asp:TextBox ID="DomainName" runat="server" Text='<%# Bind("DomainName") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DomainName"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:Button ID="btnAdd" runat="server" Text="提 交" OnClick="btnAdd_Click"/><input id="Reset1" type="reset" value="重 填" /></td>
</tr>
<tr>
<td style="width: 100px">
范围:</td>
<td style="width: 100px">
<asp:RadioButtonList ID="Scope" runat="server" Text='<%# Bind("Scope") %>'>
<asp:ListItem Value="World">国际</asp:ListItem>
<asp:ListItem Value="China">国内</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="Scope"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator></td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:Label ID="lblMessage" runat="server"></asp:Label></div>
</form>
</body>
解决方案 »
- javascript xmlhttp 定时刷新问题(请用纯JS代码,在线等待)
- datalist里面的和数据绑定的控件如何获得焦点?(高手救救俺吧,我给你们磕头了)
- char[] aaa = "##".ToCharArray;为什么报错?想用"##"来分割一个字符串怎么做?
- 关于一个datagrid的问题
- 用DataGrid显示数据 我想符号条件的行记录超连接不可用 怎么做?
- .net中我在数据层的类里写了很多sql语句,可是,我怎么输出这些sql语句呢?
- UEDITOR在VS调试可以传图片,但部署到IIS后却不行,请问怎么回事啊
- ASP.NET纯静态化,按钮事件失效怎么处理?
- 怎么样用redirect把数据传到另一页面中使用?
- 为什么服务器隔一段时间就会出现DateTime ??
- 使用 DataAccessApplicationBlock好? 还是使用 Enterprise Library 中的数据库访问助手类好??
- 单击一个linkbutton后响应一个事件后返回上一个页面?
应该改为<asp:TextBox ID="DomainName" runat="server" Text='<%# Eval("DomainName") %>'></asp:TextBox>吧
控件后再取值
Response.Write(this.DomainName.Text)
看看有值吗
{
string DataType = " server=localhost;Initial Catalog=Domain;user id=sa;password=123456 ";
TextBox aa= this.FormView1.FindControl("DomainName") as TextBox;
RadioButtonList rr = this.FormView1.FindControl("Scope") as RadioButtonList;
string updateSQL = " update DomainList set DomainName='" + aa.Text + "',Scope='"+ rr.Text +"',EditDate='" + DateTime.Now.ToShortDateString() + "' Where ID='" + Request.QueryString["ID"] + "' ";
SqlConnection Conn = new SqlConnection(DataType);
SqlCommand UpdateCmd = new SqlCommand(updateSQL, Conn);
int Added = 0;给你改了一部分,至少编译没错了,自己试试看吧