简体   繁体   English

代码背后的SqlDataSource复选框

[英]SqlDataSource checkbox before code behind

I'm populating an ASP.NET checkbox from a SqlDataSource added on the .aspx page, and then I need to access it in code behind, but I'm running into an issue in which my method is happening before the checkbox is populated and so it is giving me an item count of zero. 我正在从.aspx页上添加的SqlDataSource填充ASP.NET复选框,然后需要在后面的代码中访问它,但是我遇到了一个问题,即在填充和所以它给我的物品计数为零。

How do I make sure the checkbox is populated by the SqlDataSource before I access it with code? 在使用代码访问复选框之前,如何确保该复选框由SqlDataSource填充?

If the text label for the checkbox is getting populated, then a simple fix would be to put 如果该复选框的文本标签被填充,那么一个简单的解决方法是将

if(!(chkBox.Text == "" || chkBox.Text == null))
{
     // Your function call, or actual function code.
}

before the offending code is run in your code behind. 在您的代码后面运行有问题的代码之前。 This code prevents the if statement from being true if the label isn't populated yet. 如果标签尚未填充,则此代码可防止if语句为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM