我有一個GridView,其中一列是顯示訂單的字段,它們將顯示在我的網站的前端。不必進入編輯頁面中的每條記錄,也不必通過這種方式更改順序,只需單擊一個按鈕並使整個DisplayOrder(int)可編輯就會更方便,因此使生活變得更加簡單。如何才能做到這一點?在ASP.net GridView中編輯一個列
2
A
回答
5
2
試試這個代碼一些有用的信息:
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>Manager1</asp:ListItem>
<asp:ListItem>Manager2</asp:ListItem>
<asp:ListItem>Manager3</asp:ListItem>
<asp:ListItem>Manager4</asp:ListItem>
</asp:ListBox>
<asp:GridView ID="UserAllocationGrid" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Manager" HeaderText="Manager"
SortExpression="managers" />
<asp:TemplateField HeaderText="Allocation Percentage">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text= '<%# Bind("AllocationPercentage") %>' BorderStyle="None"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代碼隱藏
void fillGV()
{
DataTable UserAllocationTable = new DataTable();
UserAllocationTable.Columns.Add("Manager");
UserAllocationTable.Columns.Add("AllocationPercentage");
// go through listbox1 to find selected managers = selectedManagersList
List<string> selectedManagersListDates = new List<string>();
int counterR = 0;
foreach (ListItem strItem in ListBox1.Items)
{
//selectedManagersListDates.Add(strItem.Value);
DataRow drManagerName = UserAllocationTable.NewRow();
UserAllocationTable.Rows.Add(drManagerName);
UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value;
counterR = counterR + 1;
}
// ViewState["UserAllocationTable"] = UserAllocationTable;
UserAllocationGrid.DataSource = UserAllocationTable;
UserAllocationGrid.DataBind();
}
使用這一空白在任何情況下,我做到了在A按鈕點擊
protected void Button1_Click(object sender, EventArgs e)
{
fillGV();
}
0
你可以試試這個使用的ShowDeleteButton =「真」在ASP CommandField中,你可以做的GridView edidable: -
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
可能幫助你
0
你可以嘗試以下:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton = "true">
<Columns>
<asp:BoundField DataField="prodId" HeaderText="Product Id" SortExpression="prodId" ReadOnly = "true" />
<asp:BoundField DataField="prodQuantity" HeaderText="Quantity"
SortExpression="prodQuantity" ReadOnly = "true" />
</Columns>
</asp:GridView>
在Gridview
水平集AutoGenerateEditButton = "true"
。這將使用戶能夠編輯行。 在數據字段級別,使用ReadOnly = "true"
可防止編輯特定字段(在行中)。
希望這會有所幫助。
0
你可以試試這個,它會給文本框列
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>'></asp:Label>
<asp:TextBox ID="Description" runat="server"
Text='<%# Eval("Description") %>' Width="175px"
visible="false"></asp:TextBox>
</ItemTemplate>
0
這link了我一直在尋找的答案。如果您有自定義數據源,則必須處理編輯由GridView引發的每個編輯事件。在我的情況下:
Protected Sub gMaterias_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles gMaterias.RowCancelingEdit
gMaterias.EditIndex = -1
BindData()
End Sub
Protected Sub gMaterias_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles gMaterias.RowEditing
gMaterias.EditIndex = e.NewEditIndex
BindData()
End Sub
Protected Sub gMaterias_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles gMaterias.RowUpdating
lError.Visible = False
lError.Text = ""
Dim idMateria As Integer = e.Keys(0)
Dim row As GridViewRow = gMaterias.Rows(e.RowIndex)
Dim tbl As DataTable = Session("Materias")
tbl.Rows(row.DataItemIndex)("universidad") = CType(gMaterias.Rows(e.RowIndex).Cells(5).Controls(0), TextBox).Text
Dim calf = CType(gMaterias.Rows(e.RowIndex).Cells(6).Controls(0), TextBox).Text
If IsNumeric(calf) Then
tbl.Rows(row.DataItemIndex)("calificacion") = calf
Else
lError.Visible = True
lError.Text = "La calificación no es válida"
End If
gMaterias.EditIndex = -1
BindData()
End Sub
相關問題
- 1. 編輯一個GridView列的代碼asp.net
- 2. asp.net gridview編輯
- 3. ASP.NET GridView編輯
- 4. Asp.net 2.0 Gridview編輯
- 5. ASP.NET編輯GridView行
- 6. 在GridView中編輯一行
- 7. 直接在gridview中編輯一個值
- 8. 在gridview中編輯同一個單元
- 9. Asp.net MVC GridView的編輯列選項
- 10. ASP.NET GridView - 編輯動態模板列
- 11. Gridview禁用編輯1列asp.net
- 12. 在ASP.Net中批量編輯GridView
- 13. 在GridView ASP.NET C中編輯ASP按鈕#
- 14. 無法在ASP.NET Gridview中編輯空值
- 15. Asp.net gridview編輯沒有編輯按鈕
- 16. ASP.NET GridView允許編輯某一行
- 17. Gridview編輯後排序ASP.NET
- 18. 編輯其中一個GridView字段
- 19. 編輯ASP.NET中的XML Gridview的函數
- 20. 在ASP.NET中編輯GridView時發生的問題:GridView變爲空
- 21. asp.net gridview的編輯模板編程
- 22. 編輯code.How從asp.net使用vb.net下拉列表中顯示gridview
- 23. ASP.NET GridView:如何在編輯模式下控制列的格式?
- 24. 在GridView中編輯嵌套的GridView
- 25. GridView:在GridView中編輯底層數據
- 26. 在一列中帶gridview中的編輯和刪除按鈕
- 27. 如何在asp.net中以編程方式編輯gridview?
- 28. 編輯一個asp.net DropdownList
- 29. 一個GridView結合在asp.net列表C#
- 30. 編輯後得到一個gridview列標題
如何檢索Save()方法的值? – RonaldPaguay