Reputation: 1490
I am using RadGrid
with rowcontextmenu
. When I right click on a RadGrid row and select 'edit option' it will open a popup window.
What I need is when I right click on a Radgrid row, I just want to get the values of 3 columns for that particular selected row. For example, when I right click on a selected Radgrid row I want to get Customer name
, Headend name
, Site name
values of that selected row.
Here is my code:
<MasterTableView GridLines = "None" DataKeyNames="orderId" CommandItemDisplay="Top"
EditMode="EditForms">
<Columns>
<telerik:GridClientSelectColumn UniqueName = "ClientSelectColumn" HeaderStyle-Width="3%"
ItemStyle-Width="3%">
<HeaderStyle Width = "3%" ></ HeaderStyle >
<ItemStyle Width="3%"></ItemStyle>
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn UniqueName = "sId" HeaderText="sId" DataField="sId" ReadOnly="true"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "orderId" HeaderText="orderId" Visible="false"
ReadOnly="true" DataField="orderId">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Customer Name" HeaderText="Customer Name" DataField="Customer Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Market Name" HeaderText="Market Name" DataField="Market Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "LOB" HeaderText="LOB" DataField="LOB" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Headend Name" HeaderText="Headend Name" DataField="Headend Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Project Name" HeaderText="Project Name" DataField="Project Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName = "Site Name" HeaderText="Site Name" DataField="SiteName"
ReadOnly="true">
<ItemTemplate>
<asp:LinkButton ID = "lnkSiteName" runat="server" Text='<%# Eval( "Site Name" ) %>'
ForeColor="Blue" CommandName="sitename"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName = "Task Status" HeaderText="Task Status" DataField="Task Status"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Clarify Account Nbr" HeaderText="Clarify Account Nbr"
DataField="Clarify Account Nbr">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Site ID" HeaderText="Site ID" DataField="Site ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Quote ID" HeaderText="Quote ID" DataField="Quote ID">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName = "EDP Created?" HeaderText="EDP Created?" DataField="EDP Created?">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName = "EditCommandColumn" Display="false">
</telerik:GridEditCommandColumn>
</Columns>
</Mastertableview>
protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
{
int radGridClickedRowIndex;
radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]);
switch (e.Item.Text)
{
case "Edit Task":
string OrdID = rg200.MasterTableView.DataKeyValues[radGridClickedRowIndex]["orderId"].ToString();
lblOrdHeadName.Text = rg200.MasterTableView.NamingContainer.FindControl("Headend Name").ToString();
Session["orderId"] = OrdID;
ifrmPopups.Style.Add("height", "409px");
StringBuilder Script = new StringBuilder();
Script.Append("document.getElementById('ctl00_PagePlaceholder_WinEditForm_C_ifrmPopups');openpopups()");
RadAjaxManager1.ResponseScripts.Add(Script.ToString());
rg200.Rebind();
break;
}
}
If you see the above code, I am able to get the orderId
value for that selected column. But when I am trying to get Headend Name
value I am getting an error. How to get the Headend Name
value for selected row?
Upvotes: 3
Views: 56957
Reputation: 1490
I found the solution:
GridDataItem item = (GridDataItem)rg200.MasterTableView.Items[radGridClickedRowIndex];
lblOrdHeadName.Text = item["HeadendName"].Text;
Upvotes: 1
Reputation: 447
Try the following. It worked for me.
GridDataItem item =(GridDataItem)rg200.MasterTableView.Items[rg200.SelectedItems[0].ItemIndex];
lblOrdHeadName.Text = item["HeadendName"].Text;
Upvotes: 6
Reputation: 2266
Try out this code to get the Headend Name
value from the right-clicked row:
lblOrdHeadName.Text = (rg200.MasterTableView.FindItemByKeyValue("orderId") as GridDataItem)["Headend Name"].Text;
Upvotes: 1
Reputation: 99
You can use the following code to loop through the selected items and store the ID values into an array and thereby pass it to a method. Also set the EnablePostBackOnRowClick
property of the grid to true
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
string[] array = new string[10];
int i = 0;
if (e.CommandName == "RowClick")
{
foreach (GridDataItem item in RadGrid1.SelectedItems)
{
array[i] = item.GetDataKeyValue("EmpID").ToString(); // storing to array
i++;
}
}
}
Upvotes: 1