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 ObjectDataSourc e with 2 insert
parameters (I put the code below too).
ServiceConfigur ation.aspx ("Actions" column in the GridView)
<asp:TemplateFi eld HeaderText="Act ions">
....
<FooterTemplate >
<asp:Button id="cmdAddURL" runat="server" Text="Add"
__designer:wfdi d="w4" CommandName="Ad dURL"></asp:Button>
</FooterTemplate>
....
</asp:TemplateFie ld>
ServiceConfigur ation.aspx.cs:
protected void gridTargetURLs_ RowCommand(obje ct sender,
GridViewCommand EventArgs e)
{
if (e.CommandName. Equals("AddURL" ))
{
string url =
((TextBox)gridT argetURLs.Foote rRow.FindContro l("txtNewURL")) .Text;
string szNumberOfPages =
((TextBox)gridT argetURLs.Foote rRow.FindContro l("txtNewURLNPa ges")).Text;
DS_Urls.InsertP arameters["url"].DefaultValue = url;
DS_Urls.InsertP arameters["numberOfPa ges"].DefaultValue =
szNumberOfPages ;
DS_Urls.Insert( );
}
}
Now the ObjectDataSourc e stuff (you could use any other data source
though):
ServiceConfigur ation.aspx:
<asp:ObjectData Source
ID="DS_Urls" runat="server" DeleteMethod="O DS_TargetURLDel ete"
InsertMethod="O DS_TargetURLIns ert"
OnObjectCreatin g="DS_Urls_Obje ctCreating"
SelectMethod="O DS_TargetURLSel ect" TypeName="CWSer vice"
UpdateMethod="O DS_TargetURLUpd ate">
<InsertParamete rs>
<asp:Paramete r
Name="url" Type="String" />
<asp:Paramete r
Name="numberOfP ages" Type="String" />
</
InsertParameter s>
<DeleteParamete rs>
<asp:Paramete r
Name="id" Type="Int32" />
</
DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r
Name="id" Type="Int32" />
<asp:Paramete r
Name="url" Type="String" />
<asp:Paramete r
Name="numberOfP ages" Type="String" />
</
UpdateParameter s>
</
asp:ObjectDataS ource>
ServiceConfigur ation.aspx.cs:
public void ODS_TargetURLIn sert(string url, string numberOfPages)
{
targetURLs.Add( new CWTargetURL(url ,
int.Parse(numbe rOfPages)));
}
Hope this helps!
Manuel Ricca
On Dec 5, 1:31 am, shapper <mdmo...@gmail. comwrote:
On Dec 4, 7:37 pm, shapper <mdmo...@gmail. comwrote:
Hello,
I am working with a ListView but I suppose that with a GridView might
be the same.
Instead of having an Insert Button on each GridView row I would like
to have only one Insert button, for example, in the GridView footer.
When this button is clicked it should put the GridView in Insert Mode
and the EditTemplate should be showed, maybe (?), in the last GridView
row.
Do you understand what I mean?
Any idea how to do this?
Thanks,
Miguel
Please, what I need is something like what you find in the following
ComponentArt Grid:
http://www.componentart.com/webui/de...pecific/grid/f...
See the button "Add Row" on bottom.
When this button is clicked the Grid goes to Edit mode and the data is
inserted in a new row after the last row.
This is what I need to do.
Any idea?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -