Gridview的footer模板中放置控件实现添加功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<asp:GridView ID= "GridView1" runat= "server" ShowFooter= "true" AutoGenerateColumns= "false" >
<Columns>
<asp:TemplateField HeaderText= "编号" >
<ItemTemplate>
<%#Eval( "EmpID" ) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "姓名" >
<ItemTemplate>
<%#Eval( "EmpName" ) %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID= "TextBox1" runat= "server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "性别" >
<ItemTemplate>
<%#Eval( "EmpSex" ) %>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList AutoPostBack= "true" ID= "DropDownList1" runat= "server" >
<asp:ListItem Text = "请选择" Value= "0" ></asp:ListItem>
<asp:ListItem Text = "男" Value = "1" ></asp:ListItem>
<asp:ListItem Text = "女" Value = "2" ></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "地址" >
<ItemTemplate>
<%#Eval( "EmpAddress" ) %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID= "TextBox2" runat= "server" ></asp:TextBox>
<asp:Button ID= "Button1" OnClick= "AddClick" runat= "server" Text= "添加" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
protected void Page_Load( object sender, EventArgs e)
{
if (!IsPostBack)
{
databind();
}
}
public void databind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ "Conn" ].ToString());
SqlCommand cmd = new SqlCommand( "SELECT * FROM T_Users" , con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this .GridView1.DataSource = ds.Tables[0];
this .GridView1.DataKeyNames = new string [] { "EmpID" };
this .GridView1.DataBind();
}
public void AddClick( object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ "Conn" ].ToString());
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Insert into T_Users(EmpName,EmpSex,EmpAddress) values(@a,@b,@c)" ;
SqlParameter[] sp = new SqlParameter[3];
sp[0] = new SqlParameter( "@a" , SqlDbType.NVarChar, 20);
sp[1] = new SqlParameter( "@b" , SqlDbType.NVarChar, 4);
sp[2] = new SqlParameter( "@c" , SqlDbType.NVarChar, 50);
sp[0].Value = ((TextBox) this .GridView1.FooterRow.FindControl( "TextBox1" )).Text.Trim();
sp[1].Value = ((DropDownList) this .GridView1.FooterRow.FindControl( "DropDownList1" )).SelectedItem.Text;
sp[2].Value = ((TextBox) this .GridView1.FooterRow.FindControl( "TextBox2" )).Text.Trim();
cmd.Parameters.AddRange(sp);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
databind();
}
|
Gridview的footer模板中放置控件实现添加功能相关推荐
- UWP 查找模板中的控件
UWP 查找模板中的控件 原文:UWP 查找模板中的控件 这个标题我也不知道咋起,意思说一下你就明白. 1. 对官方控件的模板进行定制修改,以满足多样化需求,还有漂亮的UI 比如ListView,Gr ...
- ASP.NET Repeater 头模板(HeaderTemplate)和FooterTemplate模板中查找控件
//在HeaderTemplate中寻找Label1,默认为第0个 string s=((Label)Repeater1.Controls[0].FindControl("Label1&qu ...
- ASP.NET中Repeater控件实现分页功能
Repeater 轻量级,完全的自定义 Repeater分页,需要依靠PagedDataSource.这个类存在于System.Web.UI.WebControls命名空间.它的作用是作为数据源与数据 ...
- Silverlight中使用控件模板的问题(自己添加控件的方法)
在一步一步学Silverlight 2系列(9):使用控件模板中 WatermarkedTextBox控件可以为用户的输入提供一段提示信息,如果只是简单的一点文字信息,有时候未免显得单调,如果加上相应 ...
- asp.net panel 加html,ASP.NET 页面中动态增加的控件、添加事件
要求:页面上有一个Add按钮,每点击一次该按钮,页面上动态创建一个WebPartZone! 提醒:WebPartZone只能在OnInit或之前才能创建,否则报异常! 大家都知道,按钮的点击事件是在R ...
- 【ASP.NET】第八课——GridView 控件的编辑功能优化,GridView控件中嵌套DropDownList控件
知识点:掌握 GridView 的编辑.高亮显示的功能 .GridView控件中嵌套DropDownList控件获取数据源. [ASP.NET]第七课--数据绑定和 GridView 控件的使用 重点 ...
- .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】...
1.首先在前台dataGridview属性中增加onRowDataBound属性事件 2.然后在后台Observing_RowDataBound事件中增加代码 protected void Obser ...
- 在Repeater控件,Repeater1控件中都有FooterTemplate模板.但你在后台中如何去找FooterTemplate中的控件呢?...
在Repeater控件,Repeater1控件中都有FooterTemplate模板.但你在后台中如何去找FooterTemplate中的控件呢? 如.<FooterTemplate> ...
- Tips/Tricks#0:母版页中对控件ID的处理
注:此系列记录在我实际开发中遇到的问题和收藏一些技巧文章. 本篇技巧和诀窍记录的是:母版页中对控件ID的处理. 一.问题提出 由于总体排版和设计的需要,我们往往创建母版页来实现整个网站的统一性,最近我 ...
最新文章
- 他被导师半夜敲门叫醒:你得诺贝尔奖了!还曾为5G频谱拍卖设计方案,担任谷歌IPO咨询顾问...
- JNI 实战全面解析
- unity3d Sentinel key not found (H0007)解决方法
- DL之PSPNet:PSPNet算法的简介(论文介绍)、架构详解、案例应用等配图集合之详细攻略
- html 编辑xml,编辑XML\HTML时取消浏览“amp”
- 通用mapper版+SpringBoot+MyBatis框架+mysql数据库的整合
- java中map函数指针_如何用Rust编写合适的map函数?
- 关于Access的日期比较和空值判断
- MapReduce Shuffle详解
- 天天生鲜项目需求分析——基于Django框架的天天生鲜电商网站项目系列博客(一)...
- R语言入门之R与RStudio的详细安装过程(图文很详细哦!!!)
- FPN网络和RPN网络介绍
- 如何用python做无限弹窗_Python无限弹窗,开机启动,打包为exe程序
- php存省市,PHP格式化全国省市区列表
- 3D打印——从solidworks到打印机(含打印机常见问题及解决方法)
- [弗曼学习法] Study for learning methods
- 健身机构如何入局知识付费?
- 电脑生成siri语音_给电脑里装个Siri!海尔智能语音系统体验
- 万兴pdf编辑解压后打不开_如何使用万兴PDF专家编辑PDF文档?
- 第9期 | 家系、肿瘤临床基因组/外显子组数据分析实战
热门文章
- 将视频分成一帧一帧python_python ffmpeg任意提取视频帧的方法
- jsp实现html注册,jsp+servlet实现最基本的注册登陆功能
- redis java客户端配置,Java的Redis客户端选择-jedis与Lettuce
- MyBatis 批量更新,批量更新
- Python邮件发送案例
- 处理数字_2_计算某列的平均值
- Excel单因素方差分析
- 怎么将数据进行正太转化_想要将电脑音频进行录制怎么操作
- 学完html4需要学什么,学完了html4,再学习html5需要重点学习什么??
- OpenCV图像发现轮廓函数findContours()的使用