0
<asp:TemplateField HeaderText="Employee ID" HeaderStyle-BackColor="#0033cc" HeaderStyle-ForeColor="White" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label runat="server" ID="ONE" Text='<%#Eval("REG_ID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" HeaderStyle-BackColor="#0033cc" HeaderStyle-ForeColor="White" ItemStyle-Width="20%">
<ItemTemplate>
<asp:Label runat="server" ID="TWO" Text='<%#Eval("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View" HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="White" ItemStyle-Width="5%">
<ItemTemplate>
<asp:LinkButton ID="report" class="btn btn-warning btn-sm" Text="Report to HR" runat="server" OnClick="report_Click" />
</ItemTemplate>
</asp:TemplateField>
以上是我的GridView的代碼。當我點擊按鈕時,我想從GridView中獲取A和B的值。任何想法如何執行此?c#從gridview獲取值
protected void report_Click(object sender, EventArgs e)
{
GridViewRow theClickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
if (theClickedRow != null)
{
Label FIRST = theClickedRow.FindControl("ONE") as Label;
Label SECOND = theClickedRow.FindControl("TWO") as Label;
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + FIRST + SECOND + "');", true);
}
}
結果,我總是得到:系統網絡用戶界面控制系統工作的網頁介面控制
試試這個,標籤具有Text屬性我想這是你正在尋找'ClientScript.RegisterStartupScript(的GetType()的一個,「警報」 ,「alert('」+ FIRST.Text + SECOND.Text +「');」,true);' –