Open a Custom Information Form from Radgrid

8 posts, 0 answers
  1. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 15 Apr 2013 Link to this post

    I have a radgrid with information I am binding from a database. I have added a GridTemplateColumn with a custom button in it that I want to use for "info" about the item in that row. I already have a custom edit form as well so I cannot use that method for this. What I want to do is when the user clicks my "info" button have a form open up that has another radgrid in it with only the specific information I will pull from my database in it.

    The issue is that I do not know how to get the unique key out of the base RadGrid so that I can pass it to my query in the separate "info" page. Any guidance will be greatly appreciated.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2013 Link to this post

    Hi,

    One suggestion is that you can pass the Datakeyname as shown below.
    aspx:
    <MasterTableView DataKeyNames="Id">

    c#:
    protected void Button2_Click(object sender, EventArgs e)
    {
            foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
            {
                string value = item.GetDataKeyValue("Id").ToString();
            }
    }

    Thanks,
    Shinu
  3. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 16 Apr 2013 Link to this post

    Hi Shinu,

    Thank you for the reply. This definitely works but in the loop it is getting the value for all rows. Is there a way to get the Id for only the row the user has clicked the info button for? It does not seem as though the grid knows what row the button belongs to. When I click the edit button the grid knows that I want to edit the row that the edit button is associated with. I need this same result from the custom info button I built for each row.



    **EDIT**
    I have made some progress. What I did was create a GridButtonColumn instead of a GridtemplateColum and used the itemCommand to grab the id like this:
    var tested = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["station_id"];


    if there is a way to use an ASP Image button to do this exact same thing please let me know as I would like that much more than this.

    Thanks
  4. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 16 Apr 2013 Link to this post

    Now I have cause myself another issue. Before I had an ASP button with an onclick so I was able to open the new window as I wanted. With the GridButtonColumn it appears as though I do not have access to an onClick so how do I open the new window? I have tried all the normal methods of inserting javascript to do this but it is not working.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2013 Link to this post

    Hi,

    Try the following code to open window.
    C#:
    void RadGrid5_ItemDataBound(object sender, GridItemEventArgs e)
    {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                LinkButton link = (LinkButton)item["Uniquename"].Controls[0];
                link.OnClientClick="Open();return false;"
            }
    }
    JS:
    function Open() {
     window.radopen("RadWindow2", null);
    }

    Thanks,
    Shinu
  6. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 17 Apr 2013 Link to this post

    Thanks this works to open the new window but has introduced another issue. After adding this ItemDataBound event code to my radgrid, the ItemCommand no longer fires when I click the button. Any ideas?
  7. rdmptn
    rdmptn avatar
    72 posts
    Member since:
    Aug 2011

    Posted 19 Apr 2013 Link to this post

    The return false; statement prevents the postback. With a full postback the RadWindow will be lost, so you either need to use AJAX and dispose only the grid (thus, you can remove return false;), or use two different buttons.
  8. John
    John avatar
    17 posts
    Member since:
    Apr 2013

    Posted 19 Apr 2013 Link to this post

    Yeah I did it like this

    protected void policeGrid_ItemCommand(object sender, GridCommandEventArgs e)
            {
                if (e.CommandName == "Info")
                {
                    var stationId = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["station_id"];
                    Session["station_id"] = stationId;
     
                    radAjaxMgr.ResponseScripts.Add("radopen('information.aspx','null')");
                }
            }


    This gets me my grid data to pass to my query and allows me to pop open the new window.
Back to Top