取決於GridView列中複選框的狀態,是否可以更改鏈接按鈕的文本?取決於GridView中的複選框控件的Asp鏈接按鈕文本
查看:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" OnRowCommand="FireRowCommand" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="False" ShowDeleteButton="False" />
<asp:TemplateField HeaderText="Approve">
<ItemTemplate>
<asp:LinkButton ID="approveBtn" runat="server" CommandArgument='<%# Eval("Id") %>'
CommandName="ApproveCmd" Text="Mark Approved" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="Telephone" HeaderText="Telephone" SortExpression="Telephone" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="BusinessName" HeaderText="BusinessName" SortExpression="BusinessName" />
<asp:CheckBoxField DataField="IsVerified" HeaderText="IsVerified" SortExpression="IsVerified" />
<asp:CheckBoxField DataField="IsNewsletter" HeaderText="IsNewsletter" SortExpression="IsNewsletter" Visible="false"/>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
</Columns>
我想文字更改爲「馬克未批准」如果IsVerified是真實的。
代碼隱藏:
protected void FireRowCommand(object sender, GridViewCommandEventArgs e)
{
var command = e.CommandName;
var clientId = Convert.ToInt32(e.CommandArgument);
switch (command)
{
case "ApproveCmd":
var service = new WholesaleClientService();
service.ToggleClientVerfication(clientId);
break;
}
}
感謝。但是,我沒有在我的複選框上獲得.Checked屬性。我錯過了什麼嗎? –
編輯我的回覆,但你可能需要定製它 –
這工作,除了我發現我不能添加一個ID屬性到我的GridView的複選框。想想我必須改變我實施這個的方式。對不起,我不擅長asp.net。我用更多的代碼更新了這個問題,以便更好地瞭解我擁有的東西。 –