编程方式插入一个文本框控件到GridView.FooterRow [英] Programmatically insert a TextBox control into GridView.FooterRow
本文介绍了编程方式插入一个文本框控件到GridView.FooterRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以修改列的列和的ItemTemplate 在 GridView控件的 HeaderRow 。但是,同样是不可能的 FooterRow 因为它是只读的。
You can modify the columns and the ItemTemplate of columns in a GridView's HeaderRow. But the same is not possible on the FooterRow since it's read-only.
有什么办法,我可以通过编程在 GridView控件控件添加一个文本框控制到FooterRow?
注:我不需要对我的控件添加数据绑定
Is there any way that I can programmatically add a TextBox control to a FooterRow in a GridView control?
Note: I don't need databinding on the controls I add.
推荐答案
是的,我有这样的尝试我和它工作得很好,这里的全code ...
Yes I have tried this myself and it works fine, here's the full code...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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" >
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
ShowFooter="True">
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> animals = new List<string>();
animals.Add("Cat");
animals.Add("Dog");
animals.Add("Horse");
GridView1.DataSource = animals;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Footer) return;
TextBox textBox = new TextBox();
e.Row.Cells[0].Controls.Add(textBox);
}
}
这篇关于编程方式插入一个文本框控件到GridView.FooterRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文