This is a migrated thread and some comments may be shown as answers.

Open a Custom Information Form from Radgrid

7 Answers 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 15 Apr 2013, 05:46 PM
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.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Apr 2013, 05:01 AM
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
0
John
Top achievements
Rank 1
answered on 16 Apr 2013, 11:46 AM
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
0
John
Top achievements
Rank 1
answered on 16 Apr 2013, 07:08 PM
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.
0
Shinu
Top achievements
Rank 2
answered on 17 Apr 2013, 03:50 AM
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
0
John
Top achievements
Rank 1
answered on 17 Apr 2013, 12:14 PM
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?
0
rdmptn
Top achievements
Rank 1
answered on 19 Apr 2013, 08:36 AM
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.
0
John
Top achievements
Rank 1
answered on 19 Apr 2013, 11:43 AM
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.
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John
Top achievements
Rank 1
rdmptn
Top achievements
Rank 1
Share this question
or