且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

填充两个列表框

更新时间:2023-10-06 14:04:22

在我离开之前...我想我发现了问题.您处置连接,然后再也不创建新的连接.您不需要处理它...但是,如果要这样做,请在之后立即将其设置为新的连接.

我正在尝试遵循逻辑...如果我离开了,请告诉我

您的页面上只有一个DropDownListBox.第一次,我不能告诉您是否应该首先检查类别或语言.我假设应该先检查语言.

如果是这样,它将使用语言"选项填充列表框.然后将CheckLanguage设置为true,将CheckCategory设置为false.这两个存储在ViewState中,应在回发时进行维护.

然后,必须将m_CheckCategory设置为true,以确保它不会加载列表框中的类别"选项.至于良好的编码,为什么不使用return;代替m_CheckCategory = true;?您无需在该代码部分中进行任何其他操作,只需退出子例程即可.

因此,下次,它会检查ViewStateCheckLanguage应该是true并且CheckCategory应该是false,这会将类别加载到列表框中.
因此,对于第一个答案,将CheckCategory设置为true的原因.

但是,对于最初的问题...您是否已第二次执行步骤以查看出了什么问题? m_DT.Columns[m_ColumnName]中有什么吗?看起来您有两个表...一个CK_Language和一个CK_Category其中只有一列...与表名称相同.列名设置正确吗?

至于标准编码实践,如果要检查m_CheckLanguagem_CheckCategoryfalse,为什么还要将它们设置为false?这与常识相反.如果m_CheckLanguage设置为true,则将假定您应该检查语言.您是否意识到您将m_DbName传递给您的OpenConnection,然后再也不使用它了?短语OpenConnection表示您只是在打开连接.尝试使用PopulateDataTable代替.您还要创建一个CommandBuilder,然后再将其用于任何用途.我也不确定dropDownListCategorydropDownListLanguage的来源.

下次,遍历每个步骤,看看它是否按照预期的方式工作.您应该第二次访问m_Con.ConnectionString并看到它已被丢弃.
Before I go off...I think I found the problem. You Dispose of the connection and then never create a new one. You don''t need to dispose of it...but if you''re going to, set it to a new connection right after.

I''m trying to follow the logic...tell me if I''m off

You have a single DropDownListBox on your page. The first time through, I can''t tell if Category or Language is supposed to be checked first. I''ll assume that Language is supposed to be checked first.

If so, it populates the listbox with Language options. It then sets CheckLanguage equal to true and CheckCategory equal to false. Those two are stored in ViewState which should be maintained on postbacks.

Then, you have to set m_CheckCategory to true to make sure it doesn''t load the Category options in the listbox. As to good coding, why not instead of m_CheckCategory = true; just use return;? You don''t need to do anything else in that section of code, you can simply quit the subroutine.

So, the next time around, it checks the ViewState and CheckLanguage should be true and CheckCategory should be false, which should load the categories into the listbox.

So, to the first answer, there''s a reason why CheckCategory is set to true.

But, to the original question...have you stepped through the second time to see what''s going wrong? Is there anything in m_DT.Columns[m_ColumnName]? It looks like you have two tables...one CK_Language and one CK_Category that have only one column in them...with the same name as the table. Are the column names set correctly?

And as to standard coding practice, why do you set the m_CheckLanguage or m_CheckCategory to false if you''re supposed to check them? That''s opposite of common sense. If m_CheckLanguage is set to true, you would assume you were supposed to check the language. And do you realize that you pass in m_DbName to your OpenConnection and then never use it? And the phrase OpenConnection implies that you''re just opening the connection. Try, PopulateDataTable instead. You also create a CommandBuilder and then never use it for anything. I''m also not sure where dropDownListCategory and dropDownListLanguage come from.

Next time, go through each step and see if it''s working the way it''s supposed to. You should have gotten to m_Con.ConnectionString the second time and see that it was disposed of.


m_CheckCategory = true;


}

if (m_CheckCategory == false)
{




此代码可能是您的问题.
您将m_CheckCategory设置为true.
然后,您运行If条件来检查是否是false 来填充其他列表框(显然永远不会运行).

您的逻辑可能需要更正.




This code could be your problem.
You set m_CheckCategory to true.
You then run a If condition to check if it is false to populate your other list box (which obviously will never run).

Your logic here might need to be corrected.