转发器控制问题 [英] Problem with repeater control
本文介绍了转发器控制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据库表,其中有两列人名和状态。 status具有VERIFIED或NOT VERIFIED值。我想绑定转发器控件以显示验证人员,而不是重复绑定未经验证的人。
i have an database table which have two columns "person name" and "status". "status" have value either VERIFIED or NOT VERIFIED. i want to bind repeater control to show verified persons first than repeat binding for not verified persons.
推荐答案
设计转发器控件
Design your repeater control
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Person.aspx.cs" Inherits="RepeaterExample.Person" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptPerson" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>Person Name</th>
<th>Status</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("PersonName") %></td>
<td><%# Eval("Status") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
使用类似
Create your method for bind repeater using view like
using System;
using System.Data;
using System.Data.SqlClient;
namespace RepeaterExample
{
public partial class Person : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RepeaterBind();
}
}
private void RepeaterBind()
{
string connectionString = "Data Source=sandeepss-PC;Initial Catalog=CodeFirst;User ID=sa; Password=123456";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Select * FROM Person", con);
IDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
DataView dv = dt.DefaultView;
dv.Sort = "Status DESC";
rptPerson.DataSource = dv;
rptPerson.DataBind();
}
}
}
这篇关于转发器控制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文