在頁面加載我執行這些代碼:如何訪問GridView中的特定行並更改其屬性?
For Each row As GridViewRow In gvRD.Rows
If dt.Rows(0).Item("AKCIJA").ToString = "unos" Then
Dim myListBox As ImageButton = DirectCast(row.FindControl("btn"), ImageButton)
myListBox.ImageUrl = "~/Images/no_edit.png"
myListBox.Enabled = False
End If
Next
有了這個,我在每行改變的ImageUrl,無論是或不喜歡「UNOS」,但我只是想改變與AKCIJA行= 「UNOS」。
這是怎麼樣子的GridView:
<asp:GridView ID="gvRD" Width="1100px" runat="server" AutoGenerateColumns="False" AllowPaging="True"
OnPageIndexChanging="gvRD_PageIndexChanging"
OnSelectedIndexChanged= "OnSelectedIndexChanged"
OnRowCommand="gvRD_RowCommand">
<PagerSettings Mode="NextPrevious" FirstPageText="First" PreviousPageText="Previous" NextPageText="Next"
LastPageText="Last" PreviousPageImageUrl="~/Images/previous_1.png" NextPageImageUrl="~/Images/next_1.png"/>
<AlternatingRowStyle BackColor="#EFEFEF" Wrap="False" Font-Italic="False" Font-Names="Arial"
Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></AlternatingRowStyle>
<RowStyle BackColor="White" Wrap="False" Font-Italic="False" Font-Names="Arial"
Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></RowStyle>
<HeaderStyle BackColor="#336699" ForeColor="White" Wrap="False" Font-Italic="False"
Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></HeaderStyle>
<Columns>
<asp:BoundField DataField="DATE" HeaderText="Date" ItemStyle-HorizontalAlign="Center" >
</asp:BoundField>
<asp:BoundField DataField="LK" HeaderText="LK" ItemStyle-HorizontalAlign="Center" HtmlEncode="False">
</asp:BoundField>
<asp:BoundField DataField="LIK" HeaderText="LIK" ItemStyle-HorizontalAlign="Center" >
</asp:BoundField>
<asp:BoundField DataField="DN" HeaderText="DN" ItemStyle-HorizontalAlign="Center" HtmlEncode="False" >
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btn" runat="server" CommandName="EditRow" CommandArgument='<%# Bind("ID")%>' ImageUrl="~/Images/edit.png" Enabled="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
這正是我想要的。萬分感謝。 – SeaSide