私は学生の情報を格納している学生用フォームを持っています。 Form Looks Like This更新CheckBoxListの値はGridViewの形式でデータベースに保存されます
以下はコードです。どのようにここにCheckBoxListの
<EditItemTemplate>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal" SelectedValue='<%# Eval("SUbjects") %>'>
<%--OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged--%>
<asp:ListItem Value="Physics">Physics</asp:ListItem>
<asp:ListItem Value="Chemistry">Chemistry</asp:ListItem>
<asp:ListItem Value="Biology">Biology</asp:ListItem>
</asp:CheckBoxList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" onCheckedChanged="onChackedChange" Text='<%# Eval("SUbjects") %>'></asp:Label>
</ItemTemplate>
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int studentid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());//Get Each Row unique value from DataKeyNames
string studentname = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;//get TextBox Value in EditItemTemplet that row is clicked
string studentage = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text;
string studentdepartment = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1")).Text;
string studentgender = ((RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("RadioButtonList1")).Text;
CheckBoxList studentsubjects = ((CheckBoxList)GridView1.Rows[e.RowIndex].FindControl("CheckBoxList1"));
SqlConnection conn = new SqlConnection("Data Source=WINCTRL-0938L38; Database=dbUni; Integrated Security=true");
conn.Open();
SqlCommand cmd = new SqlCommand("StudentUpdate", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@student_id ", studentid);
cmd.Parameters.AddWithValue("@name ", studentname);
cmd.Parameters.AddWithValue("@age ", int.Parse(studentage));
cmd.Parameters.AddWithValue("@department ", studentdepartment);
cmd.Parameters.AddWithValue("@gender ", studentgender);
cmd.Parameters.AddWithValue("@subjects ", studentsubjects);
}
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;// no row in edit mode
FillGrid();
conn.Close();
}
CREATE PROCEDURE [dbo].[StudentUpdate]
(
@student_id int,
@name varchar(50),
@age int,
@gender nvarchar(50),
@department nvarchar(50),
@subjects nvarchar(50)
)
AS UPDATE tblStudents set
[email protected],
[email protected],
[email protected],
[email protected],
[email protected]
where [email protected]_id
protected void btnSave_Click(object sender, EventArgs e)
{
String gender;
if (rdBtnMale.Checked)
gender = rdBtnMale.Text;
else
gender = rdBtnFemale.Text;
string subject = "";
if (cboxPhysics.Checked)
{
subject = cboxPhysics.Text;
}
if (cboxChemistry.Checked)
{
if (subject != "")
{ subject = subject + ","; }
subject = subject + cboxChemistry.Text;
}
if (cboxBiology.Checked)
{
if (subject != "")
{ subject = subject + ","; }
subject = subject + cboxBiology.Text;
}
In This Image I have applied changes but I am having this warning.
「動作していません」を定義しますか? 'string.Join("、 "studentsubjects);'結果を与えるのは何ですか? – VDWWD
これは私のスニペットとは関係ありません。存在しない他の場所で 'SelectedValue'を設定しています。 – VDWWD