このような何かを試してみてください:
Checked='<%# Eval("pric_c_alfsupreq").ToString().Equals("Y") %>'>
UPDATE:あなたは、古いDataGridの(あなたは、今日DataGridViewのを使用する必要があります)を使用しているので
、あなたが似た何かを持っている必要がありますこれであなたのDataGrid
定義:
<asp:DataGrid ID="Grid" runat="server" PageSize="5" AllowPaging="True"
DataKeyField="EmpId" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="No"
OnPageIndexChanged="Grid_PageIndexChanged"
OnCancelCommand="Grid_CancelCommand"
OnDeleteCommand="Grid_DeleteCommand"
OnEditCommand="Grid_EditCommand"
OnUpdateCommand="Grid_UpdateCommand">
今、あなたは、行のデータへの更新を適用しているときに実行するメソッドOnUpdateCommand ...
を参照してください:
protected void Grid_UpdateCommand(object source, DataGridCommandEventArgs e)
{
con = new SqlConnection(ConfigurationManager.AppSettings["connect"]);
char value = "N"
// You'll have to change the index here to point to the CheckBox you have in
// your DataGrid.
// It can be on index 1 Controls[1] or 2 Controls[2]. Only you know this info.
if(((CheckBox)e.Item.Cells[0].Controls[0]).Checked == true)
{
value = "Y";;
}
cmd.Parameters.Add("@pric_c_alfsupreq", SqlDbType.Char).Value = value;
cmd.CommandText = "Update command HERE";
cmd.Connection = con;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
Grid.EditItemIndex = -1;
}
は、あなたのアイデアを得る願っています。他の瞬間にこのコードが必要な場合は、OnEditCommand
、OnDeleteCommand
などに配置することができます。
でそれを呼び出しますか? DataGridまたはDataGridView? –
DataGrid私は確信しています –