我有一个RadGrid:
<telerik:RadGrid ID="rgvBoards" runat="server" AllowPaging="True" AllowSorting="True" GroupPanelPosition="Top"
OnPreRender="rgvBoards_PreRender" DataSourceID="odsBoard">
<GroupingSettings CaseSensitive="false"></GroupingSettings>
<MasterTableView AutoGenerateColumns="False" DataKeyNames="BoardID" DataSourceID="odsBoard" AllowFilteringByColumn="True" ShowFooter="True">
<Columns>
<telerik:GridButtonColumn UniqueName="InActivate" ButtonType="ImageButton" ImageUrl="../images/cancelDelete.gif"
CommandName="InActivate" Display="True">
</telerik:GridButtonColumn>
<telerik:GridButtonColumn UniqueName="Activate" ButtonType="ImageButton" ImageUrl="../images/greenCheck.png"
CommandName="InActivate" Display="True">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="BoardStatus" AllowFiltering="false" HeaderText="Status"
UniqueName="BoardStatus">
</telerik:GridBoundColumn>
</Columns>
<PagerStyle AlwaysVisible="true" PageSizes="10;20;30;999" />
</MasterTableView>
</telerik:RadGrid>
目标是每行只显示一个按钮。因此,当状态标记为活动(“A”)时,将显示“InActivate”按钮。
我一直在尝试使用preRender事件来实现这一目标。我知道我的preRender事件正在被读取并且对网格有影响,因为没有应用逻辑来读取BoardStatus列我可以控制哪些按钮显示:
Protected Sub rgvBoards_PreRender(ByVal sender As Object, ByVal e As EventArgs)
rgvBoards.MasterTableView.GetColumn("InActivate").Display = False
rgvBoards.MasterTableView.GetColumn("Activate").Display = False
End Sub
我已经尝试了telerik论坛及其文档中的一些建议,例如:
Protected Sub rgvBoards_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)
Dim itemValue As String = dataItem("BoardStatus").Text
If itemValue.Equals("A") Then
rgvBoards.MasterTableView.GetColumn("InActivate").Display = False
ElseIf itemValue.Equals("I") Then
rgvBoards.MasterTableView.GetColumn("Activate").Display = False
End If
End Sub
产生'item'不是'System.EventArgs'成员的问题。
读取RadGrid单元格并将其放入字符串变量的正确方法是什么?
答案 0 :(得分:0)
执行此操作的正确方法是使用'OnNeedDataSource'事件 HTML:
<telerik:RadGrid ID="rgvBoards" runat="server" AllowPaging="True" AllowSorting="True" GroupPanelPosition="Top"
OnNeedDataSource="rgvBoards_NeedDataSource" DataSourceID="odsBoard">
<GroupingSettings CaseSensitive="false"></GroupingSettings>
<MasterTableView AutoGenerateColumns="False" DataKeyNames="BoardID" DataSourceID="odsBoard" AllowFilteringByColumn="True" ShowFooter="True">
<Columns>
<telerik:GridTemplateColumn UniqueName="ImageButtonColumn">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../images/cancelDelete.gif"
CommandName="InActivate" Visible='<%# Eval("BoardStatus").Equals("A")%>'
AlternateText="InActivate" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="../images/greenCheck.png"
CommandName="Activate" Visible='<%# Eval("BoardStatus").Equals("I")%>'
AlternateText="Activate" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="BoardStatus" AllowFiltering="false" HeaderText="Status"
UniqueName="BoardStatus" DataType="System.String">
</telerik:GridBoundColumn>
</Columns>
<PagerStyle AlwaysVisible="true" PageSizes="10;20;30;999" />
</MasterTableView>
</telerik:RadGrid>
以及后端(VB):
Protected Sub rgvBoards_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
rgvBoards.DataSource = GetGridSource()
End Sub
Private Function GetGridSource() As DataTable
Dim dataTable As New DataTable()
column = New DataColumn()
column.DataType = Type.[GetType]("System.String")
column.ColumnName = "BoardStatus"
dataTable.Columns.Add(column)
Dim PrimaryKeyColumns As DataColumn() = New DataColumn(0) {}
PrimaryKeyColumns(0) = dataTable.Columns("BoardID")
dataTable.PrimaryKey = PrimaryKeyColumns
Return dataTable
End Function
允许我使用电路板状态作为决定因素让RadGrid呈现正确的图像按钮。
来源:http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html