Hello Miguel,
Check out this URL which helped me solve this problem:
http://www.koffeekoder.com/ArticleDetails.aspx?id=139
Basically you just have to edit the footer template for the column
where you want and put a button in it. Then set the CommandName for
the button and in the RowCommand event handler find out if this is the
command that was fired. Here you insert your item into the datasource
and the gridview will be updated reflecting these changes.
Here is a snippet from my own app. In this app I have a GridView with
3 columns, and in the footer I placed 2 textboxes and an "Add" button.
As you can see below, the textboxes are named txtNewURL and
txtNewURLNPages. Then I'm using an ObjectDataSource with 2 insert
parameters (I put the code below too).
ServiceConfiguration.aspx ("Actions" column in the GridView)
<asp:TemplateField HeaderText="Actions">
....
<FooterTemplate>
<asp:Button id="cmdAddURL" runat="server" Text="Add"
__designer:wfdid="w4" CommandName="AddURL"></asp:Button>
</FooterTemplate>
....
</asp:TemplateField>
ServiceConfiguration.aspx.cs:
protected void gridTargetURLs_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddURL"))
{
string url =
((TextBox)gridTargetURLs.FooterRow.FindControl("txtNewURL")).Text;
string szNumberOfPages =
((TextBox)gridTargetURLs.FooterRow.FindControl("txtNewURLNPages")).Text;
DS_Urls.InsertParameters["url"].DefaultValue = url;
DS_Urls.InsertParameters["numberOfPages"].DefaultValue =
szNumberOfPages;
DS_Urls.Insert();
}
}
Now the ObjectDataSource stuff (you could use any other data source
though):
ServiceConfiguration.aspx:
<asp:ObjectDataSource
ID="DS_Urls" runat="server" DeleteMethod="ODS_TargetURLDelete"
InsertMethod="ODS_TargetURLInsert"
OnObjectCreating="DS_Urls_ObjectCreating"
SelectMethod="ODS_TargetURLSelect" TypeName="CWService"
UpdateMethod="ODS_TargetURLUpdate">
<InsertParameters>
<asp
arameter
Name="url" Type="String" />
<asp
arameter
Name="numberOfPages" Type="String" />
</
InsertParameters>
<DeleteParameters>
<asp
arameter
Name="id" Type="Int32" />
</
DeleteParameters>
<UpdateParameters>
<asp
arameter
Name="id" Type="Int32" />
<asp
arameter
Name="url" Type="String" />
<asp
arameter
Name="numberOfPages" Type="String" />
</
UpdateParameters>
</
asp:ObjectDataSource>
ServiceConfiguration.aspx.cs:
public void ODS_TargetURLInsert(string url, string numberOfPages)
{
targetURLs.Add(new CWTargetURL(url,
int.Parse(numberOfPages)));
}
Hope this helps!
Manuel Ricca