我有一個GridView綁定了一些來自數據庫的數據,並且在ItemTemplate中有一個標籤,在EditItemTemplate中有一個標籤,它們在同一個TemplateField中。在GridView中,某些用戶在某個字段中沒有數據,如果我想爲這些用戶插入一個數據,我需要首先查找GirdView標籤,並在更新時更改edittextbox,我可以比較它們的值,例如edittextbox值不等於labeldata值然後插入, 但我無法找到rowupdating或gridview的數據綁定時標籤的值如何在gridview上的itemtemplate中找到標籤C#ASP.NET
我該怎麼辦?
我有嘗試
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int rowCount = GridView1.Rows.Count;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (rowCount >= 1)
{
Label lbDA_TEL_HK_NO = ((Label)e.Row.FindControl("lblKM_TEL"));
Session["DA_TEL_HK_NO"] = lbDA_TEL_HK_NO.Text;
}
}
}
它可以找到所有的gridview的數據,但不是我選擇
PS:我是新手,請幫我
<asp:TemplateField ItemStyle-Width = "150px" HeaderText = "香港內線">
<ItemTemplate>
<asp:Label ID="lblHK_TEL" runat="server"
Text='<%# Eval("[DA_TEL_HK_NO]")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtHK_TEL" runat="server" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" MaxLength="3"
Text='<%# Eval("[DA_TEL_HK_NO]")%>'></asp:TextBox>
</EditItemTemplate>
你能證明你的ASPX標記 – Webruster