问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

asp.net中的Datagrid如何实现动态下拉框的功能?

发布网友 发布时间:2022-04-07 20:19

我来回答

2个回答

懂视网 时间:2022-04-08 00:41

C#" AutoEventWireup="true" CodeBehind="滑动门.aspx.cs" Inherits="UI.滑动门" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title>   <link rel="stylesheet" href="css/style.css" /> </head> <body> <form id="form1" runat="server"> <div class="solidBox"> <h3 class="solidBox_title"> <asp:ListView ID="ListTitle" runat="server"> <ItemTemplate> <!--自定义模板--> <strong runat="server" id="Title" class=""> <%#Eval("Title") %> </strong> </ItemTemplate> </asp:ListView> </h3> <div class="solidBox_content"> <asp:ListView ID="ListContent" runat="server"> <ItemTemplate> <!--自定义模板--> <strong runat="server" id="Content"> <%#Eval("Content") %> </strong> </ItemTemplate> </asp:ListView> </div> </div> </form> </body> </html>

样式重置:

/*
 * 样式重置文件
 */
body,
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
form,
fieldset,
input,
textarea,
p,
blockquote,
th,
td {
 margin: 0;
 padding: 0;
 font-weight: normal;
 font-style: normal;
 font-size: 12px;
 font-family: inherit;
}
table {
 border-collapse: collapse;
 border-spacing: 0;
}
fieldset,
img {
 border: 0;
}
address,
caption,
cite,
code,
dfn,
em,
strong,
th,
var {
 font-style: normal;
 font-weight: normal;
}
ol,
ul {
 list-style: none;
}
caption,
th {
 text-align: left;
}
h1,
h2,
h3,
h4,
h5,
h6 {
 font-size: 100%;
 font-weight: normal;
}
q:before,
q:after {
 content: ‘‘;
}
abbr,
acronym {
 border: 0;
}
a {
 color: #333;
 text-decoration: none;
}
a:hover {
 text-decoration: underline;
}
/*通用父子盒子嵌套浮动问题解决,开始*/

.clearfix:after {
 content: ".";
 display: block;
 height: 0;
 clear: both;
 visibility: hidden;
}
.clearfix {
 display: inline-block;
}
* html .clearfix {
 height: 1%;
}
.clearfix {
 display: block;
}
/*通用父子盒子嵌套浮动问题解决,结束*/
/*间隙层开始*/

.space_hx {
 /*横向间隙*/
 
 clear: both;
 width: 100%;
 height: 10px;
 font-size: 1px;
 overflow: hidden;
}
.space_zx {
 /*纵向间隙*/
 
 float: left;
 width: 10px;
 font-size: 1px;
 overflow: hidden;
}
/*间隙层结束*/

 

样式:

 .solidBox {
  width: 330px;
  height: 187px;
  margin: 20px;
  border-left: #CCCCCC 1px solid;
  overflow: hidden;
 }
  /*.solidBox .solidBox_title 中间空格是父子关系,以逗号隔开是同级关系*/

  .solidBox .solidBox_title {
  height: 30px;
  line-height: 30px;
  }

  .solidBox .solidBox_title div {
   float: left;
   /*变成块级元素*/
   width: 109px;
   height: 30px;
   border: #CCCCCC 1px solid;
   text-align: center;
   border-left: none;
   font: 16px "微软雅黑";
   cursor: pointer;
   /*cursor局部鼠标的样式*/
  }

  .solidBox .solidBox_title .hover {
   background: #9D9D9D;
   color: #FFF;
  }

  .solidBox .solidBox_content {
  padding: 5px;
  border: #CCCCCC 1px solid;
  border-left: none;
  border-top: none;
  height: 157px;
  width: 327px;
  overflow: hidden;
  }

后台:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace UI
{
 public partial class 滑动门 : System.Web.UI.Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {
  DBind();
 }
 private void DBind()
 {
  SqlConnection conn = new SqlConnection("Server=.;database=Test;uid=sa;pwd=x");
  conn.Open();
  SqlCommand cmd = new SqlCommand("select * from huadongmen",conn);
  SqlDataReader reader = cmd.ExecuteReader();
  List<huadongmen> list = new List<huadongmen>();
  while (reader.Read())
  {
  huadongmen sb = new huadongmen();
  sb.Title = reader[0].ToString();
  sb.Content = reader[1].ToString();
  list.Add(sb);
  }
  reader.Close();
  conn.Close();
  ListTitle.DataSource = list;
  ListTitle.DataBind();
  ListContent.DataSource = list;
  ListContent.DataBind();
 }
 }
}


附上数据库脚本:

create database Test
go
use Test
create table huadongmen
(
 title varchar(20),
 content varchar(500)
)
go
insert into huadongmen values(‘标题一‘,‘这是标题一的内容‘)
insert into huadongmen values(‘标题二‘,‘这是标题二的内容‘)
insert into huadongmen values(‘标题三‘,‘这是标题三的内容‘)

update huadongmen set content=‘这是标题二的内容‘ where title=‘标题二‘
select * from huadongmen

 

asp.net实现数据库版动态网页滑动门

标签:

热心网友 时间:2022-04-07 21:49

可以!把打算下拉的那列变成模板列(TemplateField),在模板列中拖入下拉框,这个最好用IDE完成,完成之后看前台源码如下:(这是我的程序片段)
<asp:TemplateField HeaderText=*模板
<ItemStyle HorizontalAlign=Center VerticalAlign=Middle Width=100px /
<ItemTemplate
&nbsp;<asp:DropDownList ID=DDLContent runat=server DataTextField=模板名称 DataValueField=模板编号 AutoPostBack=True OnSelectedIndexChanged=DDLContent_SelectedIndexChanged
</asp:DropDownList
<asp:Label ID=LbtopicID runat=server Visible=False</asp:Label
</ItemTemplate
</asp:TemplateField
在后台要做两件事,1是把数据库中的数据绑定到下拉框,2是当下拉框被选择时程序要做出的反应:
1.把数据库中的数据绑定到下拉框
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)//该事件是自动生成{if (e.Row.RowType == DataControlRowType.DataRow)//如果此行是DataGrid控件数据行{string topicID = GridView.DataKeys[e.Row.RowIndex].Value.ToString();//获取本行关键字的值
//***************下面是*模板列的绑定**********************
if (((DropDownList)e.Row.FindControl(DDLContent)) != null)//我的下拉框叫DDLContent{DataSet ds = cd.getContentModel(topicID);//从数据库中取得要放入下拉框的数据
DropDownList DDLContent = (DropDownList)e.Row.FindControl(DDLContent);
DDLContent.Items.Clear();
DDLContent.DataSource = cd.listModel();
DDLContent.DataBind();//绑定
if (ds.Tables[0].Rows.Count 0)//{DDLContent.SelectedValue = ds.Tables[0].Rows[0][模板编号].ToString();}else{DDLContent.Items.Insert(0, 请选择...);//用户没进行选择时显示这行}}//******************模板列绑定结束************************}}
2.如果被绑定的下拉框被用户选择,那么。。。
protected void DDLContent_SelectedIndexChanged(object sender, EventArgs e){//下面都是我的具体业务逻辑,你把它们换成你自己的
GridViewRow GVR = (GridViewRow)((Control)sender).Parent.Parent;
DropDownList DDLC = (DropDownList)(GVR.FindControl(DDLContent));
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
我看曹刿是一个什么样的人 作文 急急急 三赞曹刿300字作文 作文 我心中的英雄曹刿300 关于翻译机离线使用的效果怎么样? 古汉语中有“不可以”这一用法吗? 文言文中"可以"的古今异意 独特嗓音的特征,一般别人模仿起来比较难 我现在还有一个月机会到13岁,想改变一下声音,还有我是个男生 根据《建筑安装工程费用项目组成》(建标[-2013144号),应列入规费的是... 我女儿的电瓶车发票,用我的身份证好上牌照吗,因她本人在异地,请帮... 狗狗在豪叫是咋了 豪叫是什么意思 玻璃钢花盆的价位一般在多少钱? 天津有没有平安银行 塘沽区哪有平安银行 天津哪里有平安银行? 天津静海有平安银行吗 静海平安银行地址 刚刚用牙线的时候,把牙线打了个结,结果现在卡在牙缝里,拔不出来了~~~~怎么办?疼死了~~~~紧急求助!! 为什么牙线在中国普及不起来? 牙线一天使用几次为最佳?? 自动牙线盒怎么填充? 哪里可以检测是不是运动神经元? 上下运动神经元有什么区别? 下腹壁反射的反射弧通过哪个神经节段? 上运动神经元与下运动神经元是怎么划分的? HIT-5 进入娱乐圈了吗?泽美道杨帆还有里面成员不错,他们现在出单曲了,进圈了吗?大神们帮帮忙 尤里的复仇在哪下载? 陈奕迅演唱会下载地址 求梶浦由记所写过的OST全部 一个人一直大声豪叫是什么回事? 阿拉斯加犬每天豪叫是什么原因 我家楼上的每天都在豪叫,有谁知道这对我们有什么不好? 老狗要死会不会豪叫? 10女儿被父母批评就抱头豪叫,是什么原因? 雄性拉布拉多犬发情都豪叫吗? 穿越造句怎么用 穿越怎么造句 能用绕过、、、拍打、、、穿越、、、流连造句 用跨过&#x22EF;&#x22EF;穿越&#x22EF;&#x22EF;到达&#x22EF;&#x22EF;造句 起步……跨过……通过……穿越……到达 造句不要课文里的,靠谱一点 这是——,我听见——。这——穿越——,与——一起——。造句 用“蚁族 浮云 穿越 潜水 重塑 杯水车薪 “任意四个造句 穿越 取决于 不约而同 不由得 相提并论 名副其实 全力以赴 造句(不要太长) 用跨过……穿越……到达……造句。。。急``` “穿越”用英文怎么翻译 &quot;穿越&quot;一词用英语怎么说 用流动,弯弯曲曲,穿梭,怎么造句子 穿越的穿怎么组词 bci是什么意思?