能不能帮我编写下代码 尽量详细点 我是新手。
解决方案 »
- Gridview e.Row.Cells[0]的样式问题
- 编辑的时候提示编辑成功,但是内容还是没有变,怎么回事?本人是菜鸟不知道什么原因?
- 急!急!纠结死了! JSON数据转换
- 三层结构,数据层向业务层应该返回datatable(dataset)还是实体类List更为合理?
- Repeater 数据上移 下移
- 比较字符串相等
- asp.net插入flash的几个问题
- asp.net 有没有一个象winform 中TabControl的控件呢?
- 小弟求助一个关于radiobutton的问题
- .net c# 前台验证textbox输入时间格式 求大神指导
- 关于GridView分页的疑惑
- 求教如何在虚拟主机上配置。net 4.0的网站
或
javascript的document.write
<asp:Repeater ID="rpt" runat="server">
<HeaderTemplate>
<table>
<tr><th>用户名</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("UserName")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>using(SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=NorthWind"))
{
string strSQL = "select * from Users";
SqlDataAdapter da = new SqlDataAdapter(strSQL,con);
DataSet ds = new DataSet();
da.Fill(ds);
this.rpt.DataSource = ds;
this.rpt.DataBind();
}
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text=‘<%#GetCon(Eval("CONTENTS"))%>’></asp:Label>
</ItemTemplate>
</asp:DataList>
前台:
<asp:Repeater ID="rptUser" runat="server" onitemcommand="rptUser_ItemCommand">
<HeaderTemplate>
<table>
<tr>
<th>用户ID</th>
<th>用户名</th>
<th>联系方式</th>
<th>操作</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("ID") %>
</td>
<td>
<%#Eval("UserName") %>
</td>
<td>
<%#Eval("Phone") %>
</td>
<td>
<asp:LinkButton ID="lbtnDelete" runat="server" CommandName="delete" CommandArgument='<%#Eval("ID") %>' OnClientClick="return confirm('确定删除?')">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
后台: protected void rptUser_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string id = e.CommandArgument.ToString();
if (string.IsNullOrEmpty(id)) return;
switch (e.CommandName)
{
case "delete":
this.Delete(id);
break;
}
} private bool Delete(string id)
{
SqlConnection conn = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=NorthWind");
string sql = "delete from User where id=" + id;
SqlCommand command = new SqlCommand(sql, conn);
conn.Open();
int result= command.ExecuteNonQuery();
conn.Close();
if (result > 0)
return true;
else
return false;
}
private void LoadData()
{
SqlConnection conn = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=NorthWind");
string sql = "select * from User";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
rptUser.DataSource = ds;
rptUser.DataBind();
}
有可能有错误,LZ原谅,新手。。
前台
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None"
>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="身份证号码" HeaderText="用户ID" ReadOnly="True" />
<asp:BoundField DataField="姓名" HeaderText="用户姓名" />
<asp:BoundField DataField="员工性别" HeaderText="性别" />
<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
后台
string strCon = "Data Source=(local);Database=数据库名;Uid=帐号;Pwd=密码";
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
public void Bind()
{
using (SqlConnection con = new SqlConnection(strCon))
{
string strSQL = "select * from Users";
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = string.Format(@"delete from 表 where 条件ID='{0}'", GridView1.DataKeys[e.RowIndex].Value.ToString());
SqlConnection sqlcon = new SqlConnection(strCon);
SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
Bind();
}
你可以试一试,我没有测试