Hello, I have the following code below that retireves values from my database that I would like to bind to the CheckBoxList control. However, I have a red line under the word "Information" that I can't seem to figure out. Please keep in mind that someone else gave me this code to use which is why i'm having issues.
// Check for CheckBox value if empty then the CheckBox is empty
foreach (DataRow Row in dtStudent.Rows)
{
if (!Information.IsDBNull(Row["testid"])) <------ Message on this line.,
{
cblTests.Items.FindByValue(Row["testid"].ToString()).Selected = true;
}
}
ASP.NETC#.NET Programming
Last Comment
Brian
8/22/2022 - Mon
Carl Tawn
Well, "Information" in your code sample must refer to either a static class, or some IDataReader derived object. The red line means it isn't recognised, which will either mean you're missing a reference/namespace or the object being refered to is out of scope.
kaufmed
Additionally, just about any time you receive a squiggly in VS (green or red), you can mouse over the offending text and you should receive a popup describing what VS is having an issue with.
Brian
ASKER
Well not sure if this helps but I tried to convert the VB code that I used before to C# and that may be where the problem is, but I don' know how to fix it :(.
VB Code:
' Check for CheckBox value if empty then the CheckBox is empty
For Each Row As DataRow In dtStudent.Rows
If Not IsDBNull(Row("testid")) Then
TestList.Items.FindByValue(Row("testid").ToString()).Selected = True
End If
Next
C# code that was convert from above.
foreach (DataRow Row in dtStudent.Rows)
{
if (!Information.IsDBNull(Row["testid"]))
{
cblTests.Items.FindByValue(Row["testid"].ToString()).Selected = true;
}
}
You must use System.Convert.IsDBNull instead of Information.IsDBNull. Information class is in Microsoft.VisualBasic assembly which is not referenced in C# projects by default.
Carl Tawn
Try:
if (System.Convert.IsDBNull(Row["testid"])){ // code here}
Just use System.Convert.IsDBNull instead of Information.IsDBNull in your first code.
Brian
ASKER
Hello everyone,
for some reason when I run my code the values are not getting populated to my CheckBoxList control. Please see what I currently have. I need the code mentioned above to bind the values from the DB to the CheckBoxList control.
foreach (DataRow Row in dtStudent.Rows)
{
if (System.Convert.IsDBNull(Row["testid"]))
{
cblTests.Items.FindByValue(Row["testid"].ToString()).Selected = true;
}
}