1. 按鈕轉成 temTemplate
aspx:
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="cancel" Text="作廢" OnClientClick="return confirm('是否確定刪除?');"></asp:LinkButton>
</ItemTemplate>
cs:
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cancel")
{
//int index = Convert.ToInt32(e.CommandArgument);
LinkButton customersGridView = (LinkButton)e.CommandSource;
GridViewRow row = (GridViewRow)customersGridView.NamingContainer;
string sMedNo = Server.HtmlDecode(row.Cells[0].Text);
}
}
2.普通的
apsx:
<Columns>
<asp:ButtonField CommandName="cancel" Text="作廢" />
</Columns>
cs:
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cancel")
{
int index = Convert.ToInt32(e.CommandArgument);
GridView customersGridView = (GridView)e.CommandSource;
GridViewRow row = customersGridView.Rows[index];
string sHospNo = Server.HtmlDecode(row.Cells[0].Text);
}
}
-----------------------------------------------------------------------------------------------------
如果要抓 沒顯示在GV上的值
其中一種簡單的辦法就是 一樣把值帶入GV但隱藏起來
可是如果直接在裡面設定 則系統是不會產生code給你去抓的
所以與RowCreated時設定
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[9].Visible = false;//隱藏欄位 (數字要自己算 從0開始)
e.Row.Cells[10].Visible = false;
e.Row.Cells[11].Visible = false;
}
}
沒有留言:
張貼留言