- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我创建了一个显示来自数据库的数据的转发器控件。当用户单击删除按钮时,它应该从数据库中获取相应的列数据并将其存储在实际上没有发生的字段中。
我附上了这个问题的整个代码。
任何人都请帮助我!
所有其他可用的解决方案都仅基于 jQuery。但我想通过 c# 来完成。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater.aspx.cs" Inherits="intern4.Repeater" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="repeaterstylesheet.css" />
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<div class="container align" >
<div class="row header">
<div class="col-sm-2">ID</div>
<div class="col-sm-2">Name</div>
<div class="col-sm-2">Class</div>
<div class="col-sm-2">Edit</div>
<div class="col-sm-2">Delete</div>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="row data">
<div class="col-sm-2"> <asp:Label ID="lblId" runat="server" Text='<%# Eval("StudentID") %>' /></div>
<div class="col-sm-2"><asp:Label ID="lblName" runat="server" Text='<%# Eval("StudentName") %>' /></div>
<div class="col-sm-2"><asp:Label ID="lblClassx" runat="server" Text='<%# Eval("StudentClass") %>' /></div>
<div class="col-sm-2"><a href="StudEdit.aspx?ID= <%# Eval("StudentID") %>">Edit</a></div>
<div class="col-sm-2">
<asp:LinkButton ID="linkbtn" runat="server" ClientIDMode="Static" CssClass="btn btn-primary" data-target="#exampleModalCenter"
data-toggle="modal" CommandArgument='<%# Eval("StudentID") %>' OnCommand="btn_clck" >
Delete
</asp:LinkButton>
</div>
</div>
<hr style="color:blue" />
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Conformation alert</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<legend class="col-form-label col-sm-2 pt-0">ID</legend>
<div class="col-sm-10">
<div class="form-check">
<asp:label id="lblStudentID" runat="server" class="form-check-label" />
</div>
</div>
</div>
<div class="form-group row">
<label for="inputName" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<asp:TextBox ID="inputName" runat="server" class="form-control" Text=""></asp:TextBox>
</div>
</div>
<div class="form-group row">
<label for="inputClass" class="col-sm-2 col-form-label">Class</label>
<div class="col-sm-10">
<asp:TextBox ID="inputClass" runat="server" class="form-control" Text=""></asp:TextBox>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<asp:Button runat="server" Text="yes" OnClick="Deletestudent" />
</div>
</div>
</div>
</div>
</form>
</body>
</html>
C#代码
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace intern4
{
public partial class Repeater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
string constr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT StudentID, StudentName, StudentClass FROM tbl_Student", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
}
}
}
protected void Deletestudent(object sender, EventArgs e)
{
int studentId = int.Parse(((sender as Button).NamingContainer.FindControl("lblId") as Label).Text);
string constr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("DELETE FROM tbl_Student WHERE StudentID = @StudentId", con))
{
cmd.Parameters.AddWithValue("@StudentId", studentId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindRepeater();
}
protected void btn_clck(object sender, CommandEventArgs e)
{
int s = int.Parse((sender as LinkButton).CommandArgument);
lblStudentID.Text = s.ToString();
string constr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
try
{
SqlCommand cmd = new SqlCommand(
"select * from tbl_Student where StudentID=" + s + "", con);
SqlDataReader sd = cmd.ExecuteReader();
while (sd.Read())
{
inputName.Text = sd.GetValue(1).ToString();
inputClass.Text = sd.GetValue(2).ToString();
}
}
catch (SqlException ex)
{
}
con.Close();
}
}
}
最佳答案
根据 this answer您必须在设置 TextBox
控件后添加以下代码:
//... Some other code
while (sd.Read()) {
inputName.Text = sd.GetValue(1).ToString();
inputClass.Text = sd.GetValue(2).ToString();
}
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script type='text/javascript'>");
sb.Append("$('#exampleModalCenter').modal('show');");
sb.Append(@"</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "MyModel",
sb.ToString(), false);
此代码将从 C# 代码隐藏填充 Bootstrap 模型。
关于c# - 如何使用 C# 代码填充引导模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51845734/
我正在尝试使用中介包在 R 中进行中介分析。我查看了有关如何执行此操作的文档,并通读了 R 提供的示例(即,我已经运行了“example(mediate)”)。尽管如此,我还是无法运行最简单的中介。理
我在我的应用程序中引导 View 时遇到问题。 我试图在 bootstrap 中获取 View 实例,以便我可以分配 View 变量等。 问题是我似乎无法按照推荐的方式来做。我可以做这个: $this
我已经遵循了几个有关运行 RMI 应用程序的教程。但是,我似乎无法使其工作,因为我一直陷入相同的错误:ClassNotFoundException。我知道这个错误意味着我将文件放在了错误的位置,但我尝
最后,我开始与 Aurelia 合作。有一个入门套件可用 Here这有助于初始化 Aurelia。但它是一个模板,应该在网站模板中使用。 我有一个预配置 WebApi项目,我想在其中使用 Aureli
对于回归问题,我有一个训练数据集: - 3个具有高斯分布的变量 - 20 个均匀分布的变量。 我的所有变量都是连续的,在 [0;1] 之间。 问题是用于对我的回归模型进行评分的测试数据对所有变量具有均
我正在尝试“拉伸(stretch)”或扩展第 1 列中的 A 部分以填充该行的高度。 1行2列: +---------------------+---------------------+ |
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我正在使用 bootstrap 4 填充功能。默认情况下,bootstrap4 中的 col 或 col-12 类在左右应用 15px 填充。我想为移动设备设置左右padding 0,所以我使用下面的
我正在尝试通过自己编写引导加载程序来引导 linux 内核,但不知道如何加载内核。 所有人都在说使用 int 13h 将扇区从硬盘加载到内存。 其中部门应该加载??加载扇区后怎么办? 如果可以的话,请
如何合并两者以创建垂直菜单?我有一个基本的路由设置(它可以工作并呈现为标准的水平菜单): Home Gallery Contact 从 react-bootst
我的应用程序中有一些状态来自服务器并且不会更改(在用户 session 的生命周期内)。此状态在 HTML 中引导。 我应该将它合并到 reducer 中作为商店的一部分吗?const bootstr
有没有办法使用 styled-components与 react-bootstrap 一起? React-bootstrap 为其组件公开了 bsClass 属性而不是 className ,这似乎与
除了 YouTube 播放器的大小之外,以下代码运行良好。我无法将其调整为我想要的大小。 我试着把 width="150"和 height="100"在 iframe 但什么也没发生。
我正在尝试使这个东西与 this one 相同。我已经打印了。但崩溃消耗不起作用。 @foreach($faqs as $faq)
我想在启动 Play 应用程序时运行一些代码。这似乎不起作用。有什么线索吗? public class Global extends GlobalSettings { @Override
我了解监督学习和无监督学习之间的区别: 监督学习是一种使用标记数据“教导”分类器的方法。 无监督学习让分类器“自行学习”,例如使用聚类。 但是什么是“弱监督学习”?它如何对示例进行分类? 最佳答案 更
我对 python 还是很陌生,所以请原谅我,如果这是非常简单的或非常错误的思考方式。 我安装了 python 2.7。根据我在运行以下代码时的理解,它列出了它查找模块的目录。 Python 2.7.
我想使用 bootstrap carousel 制作一个 slider ,但我的 slider 不滑动即使我点击按钮也不会滑动 我测试了很多其他的 bootstrap slider ,我也遇到了同样的
我正在尝试通过替换 base 形状为 (4,2) 的 2D numpy 数组按行进行采样,比如 10 次。最终输出应该是一个 3D numpy 数组。 尝试了下面的代码,它有效。但是有没有不用 for
我是 Bootstrap 的新手,现在我正在检查它的 slider 功能。简单的 slider 和动画效果 - 一切正常。 但是我看不懂,我可以做这样的东西吗? - http://www.owlcar
我是一名优秀的程序员,十分优秀!