2012-07-10 54 views
-6
<div id="divErrorCount" runat="server" class="page"> 
     <asp:GridView ID="gvsummary" runat="server" AutoGenerateColumns="False" CellPadding="0" 
      Width="940px" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
      Font-Bold="True" ForeColor="Black" Style="text-align: center"> 
      <Columns> 
       <asp:TemplateField HeaderText="Unproductive Reason"> 
        <ItemTemplate> 
         &nbsp; &nbsp; 
         <asp:Label ID="lblunprodreasons" runat="server" Text='<%# Bind("unprodreasons") %>'></asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="Count"> 
        <ItemTemplate> 
         &nbsp; &nbsp; 
         <asp:Label ID="lblCount" runat="server" Text='<%# Bind("Count") %>'></asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
      <FooterStyle BackColor="#CCCCCC" /> 
      <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> 
      <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> 
      <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> 
      <AlternatingRowStyle BackColor="#CCCCCC" /> 
     </asp:GridView>   
    </div> 

代碼隱藏:名稱「gvMyDetails」不會在目前情況下(asp.net,C#)存在的幫助,請

divErrorCount.Visible = true;      
SqlDataReader myReader3 = null; 
SqlCommand myCommand3 = new SqlCommand("SELECT unprodreasons, COUNT(unprodreasons) as Count FROM [myrecords] where username = '" + ddlrep.SelectedValue.Trim() + "' and (dates >= '" + datefrom + "' and dates <= '" + dateto + "') group by unprodreasons", myConnection); 
myReader3 = myCommand3.ExecuteReader(); 
//myReader3.Read(); 
if (myReader3.HasRows) 
{ 
    gvsummary.DataSource = myReader3; 
    gvsummary.DataBind(); 
    myReader3.Close(); 
} 
else 
{ 
    myReader3.Close(); 
    //divErrorCount.Visible = false; 
} 
+4

-1沒有照顧你自己的問題(沒有格式化,沒有解釋)。 – 2012-07-10 16:38:19

+2

代碼轉儲中不存在名稱'gvMyDetails'。錯誤發生在哪裏?發佈相關代碼。 – LittleBobbyTables 2012-07-10 16:38:22

+0

那麼,_does_它存在嗎?它沒有提到你已經發布的任何代碼。 – David 2012-07-10 16:38:51

回答

2

儘管你還沒有給出很多細節去.. 。您的網格視圖命名,而不是「gvMyDetails」

<asp:GridView ID="gvsummary" runat="server" 
+0

即時通訊設法將數據綁定到gvsummary,但不gvMyDetails – user1442828 2012-07-10 16:42:06

+0

@ user1442828:那麼錯誤發生在哪裏?我很確定編譯器不僅僅是編寫變量'gvMyDetails'。你必須在某個地方引用它。 (或者試圖,而是) – David 2012-07-10 17:20:12

0

也許你的意思是「gvmydetails」在這種情況下instated GridView控件必須使用gridviewrow 並找到控制

「gvsummary」
for (int i = 0; i < gvsummary.Rows.Count; i++) 
    { 
    GridView f =(GridView)gvsummary.Rows[i].FindControl("gvMyDetails"); 
     // you code here 
    } 
相關問題