2010-07-27 5 views
0

누구나 내게 gridview의 첫 번째 행은 머리글해야 ASP에서 넷 4에 gridview에 바인딩에 대해 갈 수있는 방법에 대해 나에게 계몽 주실 래요, 두 번째는 combobox해야합니다 각 열에 대해 그리고 세 번째는 실제 데이터 소스의 시작입니다.Gridview와 바인딩을 헤더에 콤보 상자가

당신이 상상할 수있는 것은 DataGrid의 각 열과 다른 데이터 소스 사이에 바인딩을 만드는 기능입니다. 이 바인딩은 사용자가 콤보 박스에서 값을 선택하여 만들어집니다. 그러나 내가 무엇을 시도하는지에 상관없이 나는 그것을 성취하는 것처럼 보인다.

HeaderText1 | HeaderText2 | HeaderText3 
ComboBox1 | ComboBox2 | ComboBox3 
DataRow1 | DataRow1 | DataRow1 
DataRow2 | DataRow2 | DataRow2 
DataRow3 | DataRow3 | DataRow3 
당신은에 TemplateColumn 사용하여 매우 쉽게 GRIDVIEW 컬럼에있는 DropDownList를 넣을 수 있습니다

답변

0

그래서 궁금한 사람에게는 이것이 문제의 해결책으로 보입니다.

Private Sub grdMainGrid_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdMainGrid.RowCreated 
    If e.Row.RowType = DataControlRowType.Header Then 
     For Each itm As TableCell In e.Row.Cells 
      itm.Text = GenerateHeaderHTML() 
     Next 
    End If 
End Sub 

PS : 사람이 내가 다음

:-)을 듣고 싶어요 더 나은 솔루션이 있다면 나는 GenerateHeaderHTML에있는 코드()입니다. 내 코드는 매우 구체적인 사례입니다. 그러나 원하는 모든 HTML을 사용할 수 있습니다.

Private Sub grdMainGrid_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdMainGrid.RowCreated 
      If Me.BoundedObjects IsNot Nothing Then 
       If e.Row.RowType = DataControlRowType.Header Then 
        Dim PrimitivePropertyNames As List(Of String) = ParserHelper.GetPrimitivePropertyNames(Me.BoundedObjects.ToList) 
        Dim i As Integer = 0 
        For Each itm As TableCell In e.Row.Cells 
         itm.Text = ucStockImport.CreateBindingHeaderTable(itm.Text, PrimitivePropertyNames, i.ToString) 
         i += 1 
        Next 
       End If 
      Else 
       Throw New StockImportException("ucStockImport.BoundedObjects Is Nothing") 
      End If 
     End Sub 

     Private Shared Function CreateBindingHeaderTable(ByVal HeaderText As String, ByVal PropertyNames As List(Of String), ByVal ID As String) As String 
      Return String.Format("<table><tr><td>{0}</td></tr><tr><td>{1}</td></tr></table>", HeaderText, ucStockImport.CreateBindedObjectDropDownList(PropertyNames, ID)) 
     End Function 

     Private Shared Function CreateBindedObjectDropDownList(ByVal PropertyNames As List(Of String), ByVal ID As String) As String 
      Dim strBuilder As New StringBuilder 

      strBuilder.Append(String.Format("<option value=""{0}"">{1}</option>", i, propName)) 

      Dim i As Integer = 0 

      For Each propName As String In PropertyNames 
       strBuilder.Append(String.Format("<option value=""{0}"">", i) & propName & "</option>") 
       i += 1 
      Next 

      strBuilder.Append("</select>") 
      Return strBuilder.ToString 
     End Function 
+0

GenerateHeaderHTML 메소드의 코드를 게시 할 수 있습니까? – PhilPursglove

+0

위의 코드를 찾으십시오 : ...-) –

0

: 특히 당신이 데이터 소스를 사용하고, 당신은 아주 쉽게 다른 데이터 소스에 DropDownList로 바인딩 할 수

<asp:GridView runat="server" ID="ComboboxGridView"> 
    <Columns> 
     <asp:TemplateField HeaderText="Column 1"> 
      <HeaderTemplate> 
       <asp:DropDownList runat="server" ID="Column1DropDownList" /> 
      </HeaderTemplate> 
      <ItemTemplate> 
       <asp:Label runat="server" ID="Column1DisplayLabel" Text='<%# Eval("Column1") %>' /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

과 통제 수단. 헤더의 DropDownLists를 사용하여 수행중인 작업에 대해 명확하지 않습니다. GridView에 나타나는 행을 필터링하는 것입니까?

+0

당신의 도움이 많이 있지만이 내 데이터 소스가 포함됩니다 컬럼의 양으로 내 시나리오에서 작동하지 않습니다 감사하는 디자인 타임에 알 수 없으며 따라서 templatefield를 사용하여 내 문제가 해결되지 않습니다. 내가 잠시 동안 달성하고자하는 것을 상상해보십시오. 나는 재고 품목의 번호를 포함하는 CSV 파일이 있습니다. 또한 Stock이라는 응용 프로그램에 개체가 있습니다. 사용자가 주식 파일의 속성을 내 기본 개체의 속성에 바인딩 할 수있는 표를 만듭니다. –

관련 문제