How to pass the selected row of a datagrid to another form

Discussion in 'ASP .Net Datagrid Control' started by ALI-R, Feb 14, 2005.

  1. ALI-R

    ALI-R Guest

    hi all.
    Can someone help me with this?
    I have a Datagrid, and i would like to doubkle click on a cell and open
    another form sending all the fields in that cell to the form for future
    work, how can i do this?


    Thanks for you help
     
    ALI-R, Feb 14, 2005
    #1
    1. Advertisements

  2. ALI-R

    Elton Wang Guest

    doubkle click?

    Are you talking about Win form or Web form?

    Elton Wang
     
    Elton Wang, Feb 14, 2005
    #2
    1. Advertisements

  3. It's pretty straightforward. Use ItemDataBind event to setup ondblclick
    client event for every data row click. Something like

    private void dgSelection_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    ListItemType itemType = e.Item.ItemType;
    if ((itemType == ListItemType.Pager) ||
    (itemType == ListItemType.Header) ||
    (itemType == ListItemType.Footer))
    {
    return;
    }
    e.Item.Attributes["ondblclick"] = "onRowDblClick(this)";
    }

    Javascript function onRowDblClick will look like this:
    function onRowDblClick (row){
    call showModalDialog ("AnotherForm.aspx", row, "<features>");
    }

    Eliyahu
     
    Eliyahu Goldin, Feb 14, 2005
    #3
  4. ALI-R

    Elton Wang Guest

    It is pretty good.

    Elton Wang
     
    Elton Wang, Feb 14, 2005
    #4
  5. ALI-R

    ALI-R Guest

    I'm actually using a mobile form for that respect,but I think it has the
    same fuctions as a win form.
    What I did (which I don't like at all) is that I passed the caller form to
    the child form's constructor(having the required fields defined as public in
    the caller form) ,,in the child form then I set the fields to the selected
    row's values.

    Can u suggest me a better way of doing that in windows forms?
    Thanks (I like the asp.net version too:))
     
    ALI-R, Feb 14, 2005
    #5
  6. ALI-R

    ALI-R Guest

    I tried this:
    I got an script error ,I replaced it with this and it worked (did u write
    psudo code)?
    window.showModalDialog("AnotherForm.aspx",row);

    thanks
     
    ALI-R, Feb 14, 2005
    #6
  7. Yes, it was a sort a pseudocode.

     
    Eliyahu Goldin, Feb 14, 2005
    #7
  8. ALI-R

    ALI-R Guest

    I finally passed it to the modal form,in there I don't know how to set it to
    a text box?

     
    ALI-R, Feb 14, 2005
    #8
  9. ALI-R

    Elton Wang Guest

    For win form, your approach of passing caller to child
    form via constructor is good. Or you can have a public
    write only property in child form to pass caller to it.

    For web form, you can save object to Session, then in new
    page retrieve the object from Session.

    HTH,

    Elton Wang

     
    Elton Wang, Feb 15, 2005
    #9
  10. ALI-R

    ALI-R Guest

    Thanks Elton,I'll remmeber it for web forms
     
    ALI-R, Feb 15, 2005
    #10
  11. It's not clear what exactly you are trying to achieve. Did you manage to
    read the row parameter in the child form?

    Eliyahu

     
    Eliyahu Goldin, Feb 15, 2005
    #11
  12. ALI-R

    ALI-R Guest

    That's eaxctly what I am going to do,I mean I'd like to read the row
    paramtere in the child form and pass it to a textbox.
    Thanks
     
    ALI-R, Feb 15, 2005
    #12
  13. You should do it on client side with javascript, for example in <body
    onload...> event. The parameter is available as window.dialogArguments
    property. Once you get it, you can set the value of the textbox in the same
    javascript.

    Eliyahu

     
    Eliyahu Goldin, Feb 16, 2005
    #13
  14. ALI-R

    ALI-R Guest

    but when I use the window.dialogArguments,it returns an "object".How can I
    get the value of that object in my javascript code?


     
    ALI-R, Feb 16, 2005
    #14
  15. it's a variant. it will be of the same type you've passed. in your case you
    will get the row.

    Eliyahu

     
    Eliyahu Goldin, Feb 16, 2005
    #15
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.