我正在使用RadGrid
rowcontextmenu
。当我右键单击RadGrid行并选择“编辑选项”时,它将打开一个弹出窗口。
我需要的是当我右键单击Radgrid行时,我只想获取该特定选定行的3列值。例如,当我右键单击选定的Radgrid行时,我想获得所选行的Customer name
,Headend name
,Site name
值。
这是我的代码:
<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;
}
}
如果您看到上面的代码,我可以获得该选定列的orderId
值。但是当我试图获得Headend Name
值时,我收到了错误。如何获取所选行的Headend Name
值?
答案 0 :(得分:6)
尝试以下方法。它对我有用。
GridDataItem item =(GridDataItem)rg200.MasterTableView.Items[rg200.SelectedItems[0].ItemIndex];
lblOrdHeadName.Text = item["HeadendName"].Text;
答案 1 :(得分:1)
尝试使用此代码从右键单击的行中获取Headend Name
值:
lblOrdHeadName.Text = (rg200.MasterTableView.FindItemByKeyValue("orderId") as GridDataItem)["Headend Name"].Text;
答案 2 :(得分:1)
我找到了解决方案:
GridDataItem item = (GridDataItem)rg200.MasterTableView.Items[radGridClickedRowIndex];
lblOrdHeadName.Text = item["HeadendName"].Text;
答案 3 :(得分:1)
您可以使用以下代码循环选定的项目并将ID值存储到数组中,从而将其传递给方法。同时将网格的EnablePostBackOnRowClick
属性设置为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++;
}
}
}