0

我有一个只有ItemTemplate字段的网格视图。我有(DropDownLists, Labels and TextBoxes)。我得到了DropDownListsTextBoxes完美的价值观......但我Labels总是给我返回空值。为什么?

这是我的ItemTemplates

    <asp:TemplateField HeaderText="RESPONSÁVEL"> 
        <ItemTemplate>
           <asp:DropDownList ID="Drop_Responsaveis" runat="server" Width="115px"  ></asp:DropDownList>                                        
        </ItemTemplate>
    </asp:TemplateField>

<asp:TemplateField HeaderText="PROJETO" HeaderStyle-Width="90px" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="12px">
        <ItemTemplate>
           <asp:Label ID="Lbl_Projeto" runat="server"><%# Eval("projeto") %></asp:Label>
         </ItemTemplate>
</asp:TemplateField>

<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="60px"  HeaderText="PREVISÃO Calendar"> <%-- CAMPO 4--%>
        <ItemTemplate>
            <asp:TextBox ID="TxtPrevisao" runat="server" Width="70px" Height="12px" Text='<%# Eval("previsao","{0:dd/MM/yyyy}") %>'></asp:TextBox> 
            <asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" TargetControlID="TxtPrevisao" PopupButtonID="TxtPrevisao" CssClass="MyCalendar">
            </asp:CalendarExtender>
         </ItemTemplate>
    </asp:TemplateField>

这是我codebehind如何获得这些值的展示(在 a 内Button_Click Event):

   string projeto = "",responsavel = "", previsao = "";  
foreach (GridViewRow gvr in GridView1.Rows)
   {
     Control ddl_resp = gvr.FindControl("Drop_Responsaveis");
     Control lbl_projeto = gvr.FindControl("Lbl_Projeto");
     Control TxtPrevisao = gvr.FindControl("TxtPrevisao");

    if (ddl_resp != null)
       {
          DropDownList ddl = ddl_resp as DropDownList;
          responsavel = ddl.SelectedValue.ToString();
       }
    if (TxtPrevisao != null)
       {
          TextBox preview = TxtPrevisao as TextBox;
          previsao = preview.Text;
       }
    if (lbl_projeto != null)
       {
          Label project = lbl_projeto as Label;
          projeto = project.Text;
       }
   }

projetoALWAYS的值是Empty,但在 gridview 上,它显示它的值是正常的......也许是因为那个Eval

4

0 回答 0