请教:能不能在datagrid页脚中加入web控件
能不能在datagrid页脚中加入web控件,如果能如何实现。谢谢!
------解决方案--------------------.aspx:
<asp:DataGrid ID= "Grid " runat= "server " OnItemDataBound= "Grid_ItemDataBound ">
<Columns>
<asp:BoundColumn DataField= "name "> </asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<span id= "spitem " runat= "server "> </span>
</ItemTemplate>
<FooterTemplate>
<span id= "spfoot " runat= "server "> </span>
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
populate_grid();
}
}
private void populate_grid()
{
string strconn = ConfigurationManager.ConnectionStrings[ "AMSConnectionString "].ConnectionString;
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_help ";
conn.Open();
Grid.AutoGenerateColumns = false ;
Grid.ShowFooter = true;
Grid.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
Grid.DataBind();
conn.Close();
}
protected void Grid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
HtmlGenericControl sp;
if(e.Item.ItemType ==ListItemType.Item)
{
sp = (HtmlGenericControl)e.Item.FindControl( "spitem ");
sp.InnerText = e.Item.ItemIndex.ToString();
}
if (e.Item.ItemType == ListItemType.Footer )
{
sp = (HtmlGenericControl)e.Item.FindControl( "spfoot ");
sp.InnerText = "footer ";
}
}