怎么实现asp.net代码和界面不分开写

.net CS代码和HTML代码写在一个页面的时候
怎么引用命名空间的

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

//绑定列到下拉列表框
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
for (int i = 1; i <= GridView1.Columns.Count; i++)
{
DropDownList1.Items.Add(i.ToString());
}
for (int i = 1; i <= GridView1.Rows.Count; i++)
{
DropDownList2.Items.Add(i.ToString());
}
}

}
//添加2个属性 鼠标移动颜色改变
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
//DropDownList list = (DropDownList)e.Row.Cells[8].FindControl("DropDownList3");
//Label lb = (Label)e.Row.Cells[1].FindControl("Label1");
//string tt = lb.Text;
//string sql = "select t_heton_qybaokanname from t_hetonManage where t_heton_bianhao='" + tt + "'";
//list.DataSource = Db.ExecuteSql4Ds(sql);
//list.DataBind();

}
//如果行中t_heton_jhfs的字段值等于邮局汇款 行颜色变为绿色
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// e.Row.Cells[1].Attributes.Add("onclick", "return confirm('确定删除吗?');");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string lb1 = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "t_heton_jhfs"));
if (lb1 == "未确定")
{
e.Row.BackColor = System.Drawing.Color.Green;
}
}

//for (int i = 0; i < GridView1.Rows.Count; i++)
//{

//DropDownList dd = (DropDownList)e.Row.Cells[8].FindControl("DropDownList3");
// dd.Items.Add("1");
// //string bh = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "t_heton_bianhao"));
// //string sql = "select t_heton_qybaokanname from dbo.t_hetonManage where t_heton_bianhao='" + bh + "'";
// //DropDownList dd = (DropDownList)e.Row.Cells[8].FindControl("DropDownList3");
// //DataSet ds = new DataSet();
// //ds = Db.ExecuteSql4Ds(sql);
// //dd.DataSource = ds;
// //dd.DataTextField = "t_heton_qybaokanname";
// //dd.DataValueField = "t_heton_qybaokanname";
// //dd.DataBind();
//}

}
//隐藏选中列
protected void Button1_Click(object sender, EventArgs e)
{
int col = Convert.ToInt32(DropDownList1.SelectedValue) - 1;
GridView1.Columns[col].Visible = false;
}

//显示全部列
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Columns.Count; i++)
{
GridView1.Columns[i].Visible = true;
}
}
//隐藏行
protected void Button4_Click(object sender, EventArgs e)
{
int col = Convert.ToInt32(DropDownList2.SelectedValue) - 1;
GridView1.Rows[col].Visible = false;
}
//显示行
protected void Button5_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridView1.Rows[i].Visible = true;
}
}

//全选
protected void chkAll_CheckedChanged(object sender, EventArgs e)
{

foreach (GridViewRow gr in GridView1.Rows)
{

CheckBox chk = (CheckBox)gr.Cells[6].FindControl("itemchk");
if (!chk.Checked)
{
chk.Checked = true;
}
else
{
chk.Checked = false;
}

}
}

protected void Button3_Click(object sender, EventArgs e)
{
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox ck = (CheckBox)gr.Cells[6].FindControl("itemchk");
if (ck.Checked)
{
//执行删除

//TextBox1.Text = gridview1.;

}
}
}

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{

}

protected void Button7_Click(object sender, EventArgs e)
{
foreach (GridViewRow gr in GridView1.Rows)
{

RadioButton rd = (RadioButton)gr.Cells[8].FindControl("RadioButton1");

Response.Write(rd.Checked.ToString());
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>gridview</title>
<link href="../css/StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
注意设置格式化时间必须设置HtmlEncode的值为false
<asp:GridView
ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="stye111"
DataKeyNames="t_heton_id" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True"
OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="操作" />
<asp:BoundField DataField="t_heton_id" HeaderText="t_heton_id" InsertVisible="False"
ReadOnly="True" SortExpression="t_heton_id" Visible="False" />
<asp:TemplateField HeaderText="合同编号" SortExpression="t_heton_bianhao">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("t_heton_bianhao") %>'></asp:TextBox>
</EditItemTemplate>
<ControlStyle Width="50px" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("t_heton_bianhao") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="t_heton_qianddate" DataFormatString="{0:d}" HeaderText="签订时间"
HtmlEncode="False" SortExpression="t_heton_qianddate">
<ControlStyle Height="60px" />
</asp:BoundField>
<asp:BoundField DataField="t_heton_dfqdname" HeaderText="对方签订人" SortExpression="t_heton_dfqdname">
<ControlStyle Width="40px" />
</asp:BoundField>
<asp:BoundField DataField="t_heton_qybaokanname" HeaderText="签约报刊名" SortExpression="t_heton_qybaokanname">
<ControlStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="t_heton_jhfs" HeaderText="结汇方式" SortExpression="t_heton_jhfs">
<ControlStyle Width="50px" />
</asp:BoundField>
<asp:TemplateField HeaderText="全选">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="True" OnCheckedChanged="chkAll_CheckedChanged"
Text="全选" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="itemchk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:Button ID="Button6" runat="server" CommandName="Delete" OnClientClick="return confirm('您真的要删除?')"
Text="删除" />
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
<asp:Label ID="Label1" runat="server" Text="Label">共有<%=GridView1.PageCount %>页 当前在<%=GridView1.PageIndex+1 %>页</asp:Label><br />
<asp:Button ID="Button7" runat="server" OnClick="Button7_Click" Text="Button" /><br />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="隐藏选定的列" />
<asp:Button ID="Button2" runat="server" Text="显示所有列" OnClick="Button2_Click" />
<br />
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="隐藏选定行" />
<asp:Button ID="Button5" runat="server" Text="显示所有行" OnClick="Button5_Click" />
<br />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="删除选中列" />
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox><br />
<br />
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:spiderConn %>"
InsertCommand="INSERT INTO [t_hetonManage] ([t_heton_bianhao], [t_heton_qianddate], [t_heton_dfqdname], [t_heton_qybaokanname], [t_heton_jhfs]) VALUES (@t_heton_bianhao, @t_heton_qianddate, @t_heton_dfqdname, @t_heton_qybaokanname, @t_heton_jhfs)"
SelectCommand="SELECT [t_heton_id], [t_heton_bianhao], [t_heton_qianddate], [t_heton_dfqdname], [t_heton_qybaokanname], [t_heton_jhfs] FROM [t_hetonManage]">
<InsertParameters>
<asp:Parameter Name="t_heton_bianhao" Type="String" />
<asp:Parameter Name="t_heton_qianddate" Type="DateTime" />
<asp:Parameter Name="t_heton_dfqdname" Type="String" />
<asp:Parameter Name="t_heton_qybaokanname" Type="String" />
<asp:Parameter Name="t_heton_jhfs" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

这样写就可以了
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
引用命名空间
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-01-30
<%@ Import Namespce=”System.Data.SqlClient” %>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网