사용자가 ASP.Net GridView 컨트롤을 사용하여 많은 양의 데이터를 입력 할 수있게하려고합니다. 내가 만들려고하는 영향은 GridView 컨트롤이 스프레드 시트처럼 작동하도록 만드는 것입니다. 사용자는 자유롭게 데이터와 탭을 열과 행 및 행에서 입력 할 수 있습니다. 사용자는 페이지 하단의 버튼을 사용하여 필요에 따라 행을 추가 할 수 있습니다. 또한 폼의 하단에 필요에 따라 저장할 수있는 버튼이 있습니다.DataTable을 ASP.Net GridView 컨트롤에 바인딩 할 때 문제가 발생했습니다.
이렇게하려면 빈 행이 들어있는 DataTable을 만들어 GridView에 바인딩했습니다. GridView의 열은 텍스트 상자가 포함 된 템플릿 열입니다. 따라서 페이지가 열리면 스프레드 시트처럼 보입니다. 사용자가 행 추가 버튼을 클릭하면 GridView가 바인딩 된 DataTable에 또 다른 10 개의 행을 추가하기 만하면 매력적으로 작동합니다.
내가 겪고있는 문제는 사용자가 입력 한 데이터를 읽는 것입니다. 사용자가 페이징 링크 또는 업데이트 버튼을 클릭하면 사용자가 입력 한 데이터로 DataTable을 업데이트하고 싶습니다. 여기에 제가 가진 내용이 있습니다.
Private Sub UpdateDataTable()
Dim objCatRow As clsCategoriesRow = Session("gvCategoriesRow")
Dim drQuery() As DataRow = Nothing
Dim drRow As DataRow = Nothing
Dim objRow As GridViewRow = Nothing
Dim intRecNo As Integer = 0
Dim txt As TextBox = Nothing
Dim lbl As Label = Nothing
'Loop through all of the rows in the grid view control
For Each objRow In Me.gvCategories.Rows
'Get the label that contains the identity column
lbl = objRow.Cells(GridColumns.Category).FindControl("lblItemRecNo")
intRecNo = lbl.Text
'Update the datarow bound to this grid view row
'First, query the datarow from the data table
drQuery = objCatRow.Table.Select("recno = " & intRecNo)
'Make sure our query returned a row
If Not IsNothing(drQuery) AndAlso drQuery.Count > 0 Then
'Get the value from the textbox in the grid view
txt = objRow.Cells(GridColumns.Category).FindControl("txtItemCategory")
'Upadte the data row with the value the user entered
'THE VALUE IN txt.Text IS EMPTY. HOW CAN I GET THE VALUE THE USER TYPED IN?
drQuery(0)("Category") = txt.Text
'Get the value from the textbox in the grid view
txt = objRow.Cells(GridColumns.SortORder).FindControl("txtItemSortOrder")
'Upadte the data row with the value the user entered
drQuery(0)("sortorder") = txt.Text
End If
Next
End Sub
문제는이 사용자가에 입력 한 내용 반환되지 않는다는 점이다.
이는 TXT = objRow.Cells (GridColumns.Category) .FindControl는 ("txtItemCategory")
는 반환 라인 템플리트 된 열의 텍스트 상자에 대한 참조 그러나 이전 값, 즉 사용자가 입력 한 값이 아닌 뷰 상태의 값이 포함되어 있습니다.
사용자가 그리드에 입력 한 값을 어떻게 얻을 수 있습니까?
각 행에 EDIT 및 UPDATE 버튼을 추가하는 방법을 알고 싶습니다. 할 수 있으면 그렇게하는 것을 피하고 싶습니다. 내 사용자는 거대한 데이터 목록을 가지고있어 그 접근법으로 인해 응용 프로그램을 사용할 수 없게됩니다. 사전에
감사합니다,
마이크
위의 코드에서 Page.Request.Form.Item (key) 또는 Page.Request.Form (key)을 통해 키 값을 가져옵니다. "키"는 문자열입니다. – fenone
이것은 나를 위해 훌륭했습니다! 감사! – Mikutus