Aspx フォーム:
<asp:Table ID="viewV" runat="server">
<asp:TableRow>
<asp:TableHeaderCell>Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Type</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
以下のコード:
vRepository getV = new vRepository();
var viewAllV = getV.GetV();
foreach (tblV singleV in viewAllV)
{
TableRow tr = new TableRow();
// Create four new cells for each row within the database
TableCell vName = new TableCell();
TableCell vType = new TableCell();
// Attached values to each of these cells
vName.Text = singleV.vName;
vType.Text = singleV.tblVType.vName;
// Add the cells to the table
tr.Cells.Add(vName);
tr.Cells.Add(vType);
// Add the row to the table
viewV.Rows.Add(tr);
}
現在、LINQ を使用して asp:table にデータを入力していますが、これは正常に機能しています。
public IQueryable<tblV> GetV()
{
return (from getAllV in dc.tblV
where getAllV.deleted != 1
orderby getAllV.vName
select getAllV).DefaultIfEmpty();
}
GridView/ListView/DetailsView を試しましたが、GetV にアクセスできないようです。実際のテーブルにしかアクセスできません。
ユーザーが編集/削除したい行を選択できるように、すべての行の最後に編集/削除ボタンを追加したいと考えています。
ユーザーが編集/削除ボタンを選択すると、別のビューにアクセスする必要があります (1 つは編集用、もう 1 つは追加用 - 同じ aspx ファイル内)。
例えば:
Name Type
Example 1 Type 1 Edit Button Delete Button
Example 2 Type 1 Edit Button Delete Button
「例1」の編集ボタンを選択できるようにしたい。これは次のようになります。
- 「編集ビュー」に連れて行って、
- 2 つのテキスト フィールドに正しい情報を自動入力します。
- 一意の ID(PK) を使用して新しい情報で行 (データベース内) を更新します。
その行の一意の ID を何らかの方法で保持する複数の編集/削除ボタンを作成したのはなぜですか?
私はそれが次のようなものになると思いました:
TableCell vEdit = new TableCell();
vEdit.Button = singleV.vID;
tr.Cells.Add(vEdit);