템플릿 필드가있는 gridview가 있습니다. ItemTemplate 내부의 레이블 값을 가져 오기 위해 imagebutton을 누를 때 원합니다.
<asp:GridView ID="GridView1" ShowHeader="False"
GridLines="None" AutoGenerateColumns="False"
runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="border: 0px solid">
<tr>
<td style="width: 220px">
<asp:Image ID="imgEmployee" BorderStyle="Solid" Height="182px" Width="235px"
ImageUrl='<%# Eval("Photo")%>'
runat="server" />
</td>
<td style="width: 600px">
<table>
<tr>
<td>
<b>ID:</b>
</td>
<td>
<asp:Label ID="lblId"
runat="server"
Text='<%#Eval("id")%>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Item:</b>
</td>
<td>
<asp:Label ID="lblItem"
runat="server"
Text='<%#Eval("Item")%>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Price:</b>
</td>
<td>
<asp:Label ID="lblPrice"
runat="server"
Text='<%#Eval("Price")%>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Notes:</b>
</td>
<td>
<asp:Label ID="lblNotes"
runat="server"
Text='<%#Eval("Notes")%>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text ="1" ></asp:TextBox>
</td>
<td>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/buy.png" CommandName="AddToBasket" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
GridView1_RowCommand에는 다음 코드가 있습니다.
If e.CommandName = "AddToBasket" Then
여기에서 레이블의 값을 받고 싶습니다.
첫 번째 에 OnRowCommand
이벤트 메소드 를 첨부해야합니다 GridView
.
<asp:GridView ID="GridView1" ShowHeader="False"
GridLines="None" AutoGenerateColumns="False"
OnRowCommand ="GridView1_RowCommand"
runat="server">
당신은 얻을 수 GridViewRow
commandsource의에서 NamingContainer
사용 FindControl
를 찾는 방법은 Labels
다음과 같이 :
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AddToBasket")
{
int id = 0;
string item = string.Empty; ;
decimal price = 0.00m;
string notes = string.Empty;
var gvRow = ((ImageButton)e.CommandSource).NamingContainer as GridViewRow;
var lblId = gvRow.FindControl("lblId") as Label;
var lblItem = gvRow.FindControl("lblId") as Label;
var lblPrice = gvRow.FindControl("lblId") as Label;
var lblNotes = gvRow.FindControl("lblId") as Label;
if (lblId != null && lblItem != null && lblPrice != null && lblNotes != null)
{
int.TryParse(lblId.Text, out id);
item = lblItem.Text;
decimal.TryParse(lblPrice.Text, out price);
notes = lblNotes.Text;
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다