problem in CheckListBox in asp.net [Resolved]

Posted by Nuwan under ASP.NET on 11/19/2012 | Points: 10 | Views : 1654 | Status : [Member] | Replies : 4
I have insert value using checkListbox in asp.net.
now I want if record already exits in database check(mark) the ckecklistbox.
how I do that. Please help me.

Thank You...

Rathnayake


Responses

Posted by: Krv on: 11/19/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hope, you know how to get the data from sql server
Once you got the datas in ds, you can loop like below to check the already inserted value

foreach (DataRow dr in ds.Tables[0].Rows)
{
checkBoxList.Items.FindByValue(dr["prv"].ToString()).Selected = true;
}

Thanks,
R.Vasanth
MCTS(SQL Server & BI)
http://bigdatatech.blogspot.com

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Krv on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

a.Get the all the values from the database
b. Loop the dataset and find the index of the dataset value and if the index is greater than -1 then it means that data is not exist, if the index is >=0 then check the Item of that index.

Thanks,
R.Vasanth
MCTS(SQL Server & BI)
http://bigdatatech.blogspot.com

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
Is this method can show if record exist some value field mark the checklistbox.
following code show the i insert value in checklistbox.


Dim qry As String = ""
Dim usr As String = Me.DropDownList1.SelectedValue.ToString()

Dim sqlcon As SqlConnection = New SqlConnection(GetConnectionString)

Dim list As ListItem

For Each list In CheckBoxList2.Items
If (list.Selected) Then

qry += "insert into Temp_Exe (usr,prv) values('" + usr + "','" + list.Value + "')"

End If

Next

If (qry <> "") Then

Dim sqlcmd As SqlCommand = New SqlCommand(qry, sqlcon)
sqlcmd.CommandType = CommandType.Text
sqlcon.Open()
sqlcmd.ExecuteNonQuery()
sqlcon.Close()

End If


Rathnayake

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks..........

Rathnayake

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response