Dropdown in footer template of datagrid

E

Edward Bills

I have been able to create and populate dropdowns in both the item template
tag and the edit template tag. When I try to add one to the footer the
function I have inserted into the datasource tag never gets called. What is
the proper way to populate a dropdown in the Footer Template of a DataGrid?

Thanks
Ed
 
A

Alvin Bruney [MVP]

in your itemdatabound eventhandler, are you checking if the cell is of type
footer?
 
E

Edward Bills

First I Just tried calling a function from the HTML code in the datasource
tag of the list box (The function GetAgencies returns a datatable, and the
following code works great in an edittemplate tag):

<FooterTemplate>
<asp:DropDownList runat="server" lstAddAgencies"
DataValueField="Code" DataTextField="Description" DataSource="<%#
GetAgencies() %>"></asp:DropDownList>
</FooterTemplate>

I then tried the following code:

Sub C1WebGrid2_ItemDataBound(ByVal sender As Object, ByVal e As
C1.Web.C1WebGrid.C1ItemEventArgs) Handles C1WebGrid2.ItemDataBound
If e.Item.ItemType = C1.Web.C1WebGrid.C1ListItemType.Footer Then
lstAddAgencies.DataSource = GetAgencies()
lstAddAgencies.DataBind()
lstAddNames.DataSource = GetNames()
lstAddNames.DataBind()
End If
End Sub

Neither of the above methods will populate the dropdowns in the footer.



Alvin Bruney said:
in your itemdatabound eventhandler, are you checking if the cell is of type
footer?


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Edward Bills said:
I have been able to create and populate dropdowns in both the item template
tag and the edit template tag. When I try to add one to the footer the
function I have inserted into the datasource tag never gets called. What
is
the proper way to populate a dropdown in the Footer Template of a
DataGrid?

Thanks
Ed
 
A

Alvin Bruney [MVP]

for your last function you will need to set the datatextstring property to
the value of the column you want to display otherwise it won't show

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Edward Bills said:
First I Just tried calling a function from the HTML code in the datasource
tag of the list box (The function GetAgencies returns a datatable, and the
following code works great in an edittemplate tag):

<FooterTemplate>
<asp:DropDownList runat="server" lstAddAgencies"
DataValueField="Code" DataTextField="Description" DataSource="<%#
GetAgencies() %>"></asp:DropDownList>
</FooterTemplate>

I then tried the following code:

Sub C1WebGrid2_ItemDataBound(ByVal sender As Object, ByVal e As
C1.Web.C1WebGrid.C1ItemEventArgs) Handles C1WebGrid2.ItemDataBound
If e.Item.ItemType = C1.Web.C1WebGrid.C1ListItemType.Footer Then
lstAddAgencies.DataSource = GetAgencies()
lstAddAgencies.DataBind()
lstAddNames.DataSource = GetNames()
lstAddNames.DataBind()
End If
End Sub

Neither of the above methods will populate the dropdowns in the footer.



Alvin Bruney said:
in your itemdatabound eventhandler, are you checking if the cell is of type
footer?


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
message
I have been able to create and populate dropdowns in both the item template
tag and the edit template tag. When I try to add one to the footer the
function I have inserted into the datasource tag never gets called. What
is
the proper way to populate a dropdown in the Footer Template of a
DataGrid?

Thanks
Ed
 
S

Scott G.

This code works for me:

<%@ Page language="c#" AutoEventWireup="False" Trace="true" %>
<html>
<head>
<script language="C#" runat="server">
protected override void OnLoad(EventArgs e)
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add("hi");
list.Add("there");
DG.DataSource = list;
DG.DataBind();
}

protected System.Data.DataTable GetAgencies()
{
System.Data.DataTable t = new System.Data.DataTable();
t.Columns.Add("code");
t.Columns.Add("description");
System.Data.DataRow row = t.NewRow();
row["code"] = "1";
row["description"] = "one";
t.Rows.Add(row);
row = t.NewRow();
row["code"] = "2";
row["description"] = "two";
t.Rows.Add(row);
return t;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DG" runat="server" autogeneratecolumns="False" showfooter="True" showheader="False">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server" text="Foo"></asp:label>
</itemtemplate>
<footertemplate>
<asp:dropdownlist runat="server"
DataValueField="code" DataTextField="description"
DataSource="<%# GetAgencies() %>" id="Dropdownlist1"></asp:dropdownlist>
</footertemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>
First I Just tried calling a function from the HTML code in the datasource
tag of the list box (The function GetAgencies returns a datatable, and the
following code works great in an edittemplate tag):

<FooterTemplate>
<asp:DropDownList runat="server" lstAddAgencies"
DataValueField="Code" DataTextField="Description" DataSource="<%#
GetAgencies() %>"></asp:DropDownList>
</FooterTemplate>

I then tried the following code:

Sub C1WebGrid2_ItemDataBound(ByVal sender As Object, ByVal e As
C1.Web.C1WebGrid.C1ItemEventArgs) Handles C1WebGrid2.ItemDataBound
If e.Item.ItemType = C1.Web.C1WebGrid.C1ListItemType.Footer Then
lstAddAgencies.DataSource = GetAgencies()
lstAddAgencies.DataBind()
lstAddNames.DataSource = GetNames()
lstAddNames.DataBind()
End If
End Sub

Neither of the above methods will populate the dropdowns in the footer.



Alvin Bruney said:
in your itemdatabound eventhandler, are you checking if the cell is of type
footer?


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Edward Bills said:
I have been able to create and populate dropdowns in both the item template
tag and the edit template tag. When I try to add one to the footer the
function I have inserted into the datasource tag never gets called. What
is
the proper way to populate a dropdown in the Footer Template of a
DataGrid?

Thanks
Ed
 
E

Edward Bills

I think it is just a problem with the component one datagrid I am using, because it works fine with the regular datagrid control. Thanks for the help.
This code works for me:

<%@ Page language="c#" AutoEventWireup="False" Trace="true" %>
<html>
<head>
<script language="C#" runat="server">
protected override void OnLoad(EventArgs e)
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add("hi");
list.Add("there");
DG.DataSource = list;
DG.DataBind();
}

protected System.Data.DataTable GetAgencies()
{
System.Data.DataTable t = new System.Data.DataTable();
t.Columns.Add("code");
t.Columns.Add("description");
System.Data.DataRow row = t.NewRow();
row["code"] = "1";
row["description"] = "one";
t.Rows.Add(row);
row = t.NewRow();
row["code"] = "2";
row["description"] = "two";
t.Rows.Add(row);
return t;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DG" runat="server" autogeneratecolumns="False" showfooter="True" showheader="False">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server" text="Foo"></asp:label>
</itemtemplate>
<footertemplate>
<asp:dropdownlist runat="server"
DataValueField="code" DataTextField="description"
DataSource="<%# GetAgencies() %>" id="Dropdownlist1"></asp:dropdownlist>
</footertemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>
First I Just tried calling a function from the HTML code in the datasource
tag of the list box (The function GetAgencies returns a datatable, and the
following code works great in an edittemplate tag):

<FooterTemplate>
<asp:DropDownList runat="server" lstAddAgencies"
DataValueField="Code" DataTextField="Description" DataSource="<%#
GetAgencies() %>"></asp:DropDownList>
</FooterTemplate>

I then tried the following code:

Sub C1WebGrid2_ItemDataBound(ByVal sender As Object, ByVal e As
C1.Web.C1WebGrid.C1ItemEventArgs) Handles C1WebGrid2.ItemDataBound
If e.Item.ItemType = C1.Web.C1WebGrid.C1ListItemType.Footer Then
lstAddAgencies.DataSource = GetAgencies()
lstAddAgencies.DataBind()
lstAddNames.DataSource = GetNames()
lstAddNames.DataBind()
End If
End Sub

Neither of the above methods will populate the dropdowns in the footer.



Alvin Bruney said:
in your itemdatabound eventhandler, are you checking if the cell is of type
footer?


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Edward Bills said:
I have been able to create and populate dropdowns in both the item template
tag and the edit template tag. When I try to add one to the footer the
function I have inserted into the datasource tag never gets called. What
is
the proper way to populate a dropdown in the Footer Template of a
DataGrid?

Thanks
Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top