我有刪除按鈕並確認警報工作正常。但是我想在顯示警告之前爲所選行的BackColor着色。它的工作正常,並顯示BackColor灰色查看按鈕,因爲沒有警報的查看按鈕。但它並不顯示BackColor已更改爲Delete按鈕,因爲它首先發出警報,並且在Yes上,它會發送到RowCommand事件。GridView上的突出顯示行LinkButton點擊確認提醒ASP.Net
如何更改背景色之前提醒刪除消息?
<asp:TemplateField HeaderText="Option">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" CommandName="editRecord" Width="14px" Height="14px" aria-label="Left Align"
CommandArgument='<%# Eval("DeptID") + "," + Eval("DeptName")%>' CssClass="" runat="server">
<span class="glyphicon glyphicon-pencil" style="vertical-align:top;"></span>
</asp:LinkButton>
<asp:LinkButton ID="btnDelete" CommandName="deleteRecord" Width="14px" Height="14px"
OnClientClick="javascript:return confirm('Are you sure you want to Delete highlighted row?');"
CommandArgument='<%# Eval("DeptID") + "," + Eval("DeptName")%>' CssClass="" runat="server">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="col-md-1 col-sm-1 col-xs-1 grid-label-text-align grid-height-10"></ItemStyle>
</asp:TemplateField>
--Code背後
protected void grdDept_RowCommand(object sender, GridViewCommandEventArgs e)
{
lblMessage.Visible = false;
GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int RowIndex = gvr.RowIndex;
grdDept.Rows[RowIndex].BackColor = System.Drawing.Color.LightGray;
if (e.CommandName == "editRecord")
{
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
string deptID = commandArgs[0];
string deptName = commandArgs[1];
hfDeptID.Value = deptID;
txtDeptName.Text = deptName;
//btnAdd.Text = "Update";
panel1.Visible = true;
lblMessage.Visible = false;
}
else if (e.CommandName == "deleteRecord")
{
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
string deptID = commandArgs[0];
if (ChildRecordExist(int.Parse(deptID)) == false)
{
DepartmentClass dept = new DepartmentClass();
dept.DeptID = int.Parse(deptID);
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = new TimeSpan(0, 15, 0);
using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, options))
{
if (deptID != "")
{
if (dept.Delete() == true)
{
tran.Complete();
panel1.Visible = false;
lblMessage.Visible = false;
}
}
}
LoadAllRecords("");
}
}
}
沒有明確什麼你正在尋找。我假設你想在用戶點擊行時突出顯示行,對嗎? –
感謝您回覆Piyush,我想在用戶按Delete按鈕時突出顯示行。並按Delete按鈕,它會發出警報「您確定要刪除突出顯示的行嗎?」如果用戶按是,然後刪除記錄,否則編號 – Raja
好的,所以我認爲根據您的代碼,你只是得到警告框,而不是行突出顯示,正確的? –