Insert Button. ListView or GridView. Is this possible?

Discussion in 'ASP .Net' started by shapper, Dec 4, 2007.

  1. shapper

    shapper Guest

    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
    shapper, Dec 4, 2007
    #1
    1. Advertising

  2. shapper

    shapper Guest

    On Dec 4, 7:37 pm, shapper <> wrote:
    > 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/d...atures/editing_dataCallbackMode/WebForm1.aspx

    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
    shapper, Dec 5, 2007
    #2
    1. Advertising

  3. shapper

    Manuel Ricca Guest

    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:parameter
    Name="url" Type="String" />
    <asp:parameter
    Name="numberOfPages" Type="String" />
    </
    InsertParameters>
    <DeleteParameters>
    <asp:parameter
    Name="id" Type="Int32" />
    </
    DeleteParameters>
    <UpdateParameters>
    <asp:parameter
    Name="id" Type="Int32" />
    <asp:parameter
    Name="url" Type="String" />
    <asp:parameter
    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


    On Dec 5, 1:31 am, shapper <> wrote:
    > On Dec 4, 7:37 pm, shapper <> wrote:
    >
    >
    >
    >
    >
    > > 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/demos/demos_control-specific/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 -
    Manuel Ricca, Dec 5, 2007
    #3
  4. shapper

    bartekm

    Joined:
    Aug 17, 2008
    Messages:
    7
    bartekm, Aug 19, 2008
    #4
  5. shapper

    David

    Joined:
    Nov 19, 2008
    Messages:
    1
    Could you pls suggest how to include Insert,update and delete in ListView using the ObjectDataSource???
    David, Nov 20, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper

    ListView ... Update and Insert

    shapper, Feb 8, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    1,155
    shapper
    Feb 8, 2008
  2. shapper
    Replies:
    1
    Views:
    678
    shapper
    Feb 12, 2008
  3. Philip
    Replies:
    2
    Views:
    709
    Philip
    Jul 23, 2008
  4. WebBuilder451
    Replies:
    0
    Views:
    1,957
    WebBuilder451
    Nov 7, 2008
  5. .
    Replies:
    0
    Views:
    720
Loading...

Share This Page