0
私はCheckBoxListを持っており、編集ボタンでチェックしたいと思います。データベースの列に値がある場合、それ以外の場合はチェックされません。チェックボックスリストの値はデータベースからのものです。データベースを使用してチェックボックスリストをチェックする方法
それはエラーを示しています。
Index was out of range. Must be non-negative and less than the size of the collection.
のデバッグ中:
Chk_seat.Items[j].Selected = true;
はどのように私はそれを行うことができますか?
<asp:CheckBoxList ID="Chk_seat" runat="server" RepeatDirection="Horizontal">
</asp:CheckBoxList>
public void updatefields_seat(long CarID)
{
SqlConnection cn = new SqlConnection(connection);
string qry = @"SELECT [ID]
,[ReferenceID]
,[CarID]
,[Child-Seat]
,[Leather-Seat]
,[Power-Seat]
,[Navigation-System]
,[Power-Steering]
,[Bucket-Seat]
,[IsActive]
FROM [dbo].[Seat_tbl] Where CarID=" + CarID + "";
DataSet dsSeat = new DataSet();
dsSeat = cm.GetQryInDataset(qry);
if (dsSeat.Tables.Count > 0)
{
for (int i = 0; i < dsSeat.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < dsSeat.Tables[0].Columns.Count; j++)
{
if (dsSeat.Tables[0].Rows[i]["Child-Seat"].ToString() != "")
{
Chk_seat.Items[j].Selected = true;
}
}
}
}
}
Asif.Ali
は、ここに私のコードです。ありがとう兄貴。私はあなたのコメントを読んだ後にその問題を解決しました。私はdidntの前に問題を得る。 –