2009-12-14 2 views
0

u는 aspx 페이지에서 SQL 데이터 소스를 사용하여있는 gridview를 채울 때 정렬이 잘 작동 ...어떻게 지금 내가 템플릿 필드를 사용하고 템플릿 필드

하지만를 사용하여있는 gridview으로 정렬하고 열은 코드 숨김에서 별도로 가득 및 정렬은

내 코드

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
          AutoGenerateColumns="False" 
          ondatabound="GridView1_DataBound" 
         onrowdatabound="GridView1_RowDataBound"> 


       <Columns> 
       <asp:TemplateField HeaderText="File Name" ItemStyle-Width="40%" > 
           <EditItemTemplate> 
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
           </EditItemTemplate> 
           <ItemTemplate> 
            <asp:Label ID="Label1" runat="server"></asp:Label> 
           </ItemTemplate> 
           <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
          </asp:TemplateField> 

          <asp:TemplateField HeaderText="Failure Count" ItemStyle-Width="10%" > 
           <EditItemTemplate> 
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> 
           </EditItemTemplate> 
           <ItemTemplate> 
            <asp:Label ID="Label3" runat="server"></asp:Label> 
           </ItemTemplate> 
           <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
           <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
          </asp:TemplateField> 
       </Columns></GridView> 

입니다 ... 작동하지 않는 내 코드 숨김은 다음과 같습니다

DataTable dt = new DataTable(); 
     SqlConnection connection = new SqlConnection(); 
     connection.ConnectionString = ConfigurationManager.ConnectionStrings["SumooHAgentDBConnectionString"].ConnectionString; 
     connection.Open(); 
     SqlCommand sqlCmd = new SqlCommand("SELECT FileName,FailureCount from Files where [email protected] , connection); 
     SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd); 
     sqlCmd.Parameters.AddWithValue("strID", strID); 

     sqlDa.Fill(dt); 

     if (dt.Rows.Count > 0) 
     { 
      for (int i = 0; i < dt.Rows.Count; i++) 
      { 
       string nameoffiles = dt.Rows[i]["FileName"].ToString(); 
       buFailureCode.Add(code); 
       string count = dt.Rows[i]["BuFailureCount"].ToString(); 
       buFailureCount.Add(count); 
      } 

     } 
     connection.Close(); 
    } 


protected void GridView1_DataBound(object sender, EventArgs e) 
    { 
     if (namesOfFiles.Count != 0) 
     { 
      for (int i = 0; i < namesOfFiles.Count; i++) 
      { 
       GridViewRow myRow = GridView1.Rows[i]; 
       Label Label1 = (Label)myRow.FindControl("Label1"); 

       Label Label3 = (Label)myRow.FindControl("Label3"); 
       Label1.Text = namesOfFiles[i].ToString(); 

       Label3.Text = buFailureCount[i].ToString(); 

      }}} 

답변

관련 문제