0
我有以下Telerik的網格,需要那麼當用戶點擊該代碼被執行 我被困在那裏與此Telerik的radgrid控件
去格按鈕從嵌套表到ItemCommand傳遞數據值 <telerik:RadGrid ID="grdRegions" runat="server" Skin="Metro" AllowCustomSorting="True"
ShowHeader="True" PageSize="10" ShowGroupPanel="False" OnItemCommand="grdRegions_ItemCommand"
ShowStatusBar="True" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True" DataSourceID="RegionDS" Width="500px">
<PagerStyle Mode="Slider" />
<MasterTableView DataSourceID="RegionDS" DataKeyNames="RegionCode" AllowMultiColumnSorting="True" Width="100%">
<DetailTables>
<telerik:GridTableView runat="server" DataKeyNames="RegionCode,DealerId" DataSourceID="DealerDS" AllowFilteringByColumn="True" >
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="RegionCode" MasterKeyField="RegionCode" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn SortExpression="DealerId" HeaderText="Dealer" HeaderButtonType="TextButton"
DataField="Dealer" UniqueName="DealerId">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="RegionCode" HeaderText="FDAF Region Code" HeaderButtonType="TextButton"
DataField="RegionCode" UniqueName="RegionCode" AllowFiltering="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="DealerId" HeaderText="DealerId" HeaderButtonType="TextButton"
DataField="DealerId" UniqueName="Dealer">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn ItemStyle-Width="22px" AllowFiltering="false">
<ItemTemplate>
<asp:ImageButton ID="EditDealer" runat="server" AlternateText="Edit Dealer" ToolTip="Edit Dealer"
ImageUrl="Images/edit.png" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.DealerId")%>'
CommandName="EditDealer" CausesValidation="false" />
</ItemTemplate>
<ItemStyle Width="22px"></ItemStyle>
</telerik:GridTemplateColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridBoundColumn SortExpression="RegionName" HeaderText="FDAF Region" HeaderButtonType="TextButton"
DataField="RegionName" UniqueName="RegionName" AllowFiltering="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="RegionCode" HeaderText="FDAF Region Code" HeaderButtonType="TextButton"
DataField="RegionCode" UniqueName="RegionCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="RegionDealerCount" HeaderText="Dealers In Region" HeaderButtonType="TextButton"
DataField="RegionDealerCount" UniqueName="RegionDealerCount" AllowFiltering="False">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
protected void grdRegions_ItemCommand(object sender, GridCommandEventArgs e)
{
objDealerDL.DealerId = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DealerId"].ToString());
GridDataItem item = (GridDataItem)e.Item;
if (e.CommandName == "EditDealer")
{
try
{
do work
}
catch (Exception ex)
{
}
}
}
彼得,你在這裏迷路了嗎? //將數據項轉換回作爲數據源傳入的項的類型 YourDataItemType val =(YourDataItemType)item.DataItem; //現在設置你的命令參數 btn.CommandArgument = val.ChildValue; – user1934500 2013-05-02 00:26:27
我將編輯原始答案以在此展開。 – Peter 2013-05-02 19:14:14