本文介绍了为什么我的行设置为可见后不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表有六行,但只有两个可见(一个标题行和一个业务行)。



用户可以选择一个按钮,一次添加一个添加行(实际上,它只是使现有行可见),总共六行/五个业务行。



第2-6行由代码隐藏开头隐藏:

  foapalrow3.Style [display ] =none; 

(具有与foapalrow4,foapalrow5和foapalrow6相同的代码)。



当用户选择+按钮时,它们会通过jQuery显示:

  / *这使得下一个隐藏行可见,只要有一个* / 
$(document).on(click,'[id $ = btnAddFoapalRow]',function(e){
$('[id $ = foapalhtmltable]')。find('tr:hidden:first')show();
});

这很好。问题是,当提交表单时,先前可见的行恢复为隐藏(除了前两个)。我正在尝试添加代码,如果中的任何文本输入都被赋予一个值,则会重新显示这些行。 IOW,如果我给Index列在每一行中的值如下:





....我希望他们会再次显示,因为他们有一个值:





...且其可见属性确实为true:





...但行仍保持顽固,隐藏在他们的洞穴。这是后面的代码:

  private void btnSave_Click(object sender,EventArgs e)
{
try
{
。 。 。 // code elided for brevity
ConditionallyCreateList();
SaveInputToList();
listOfListItems = ReadFromList();
message.Text =保存数据已成功;

//显示带有vals的行
if(RowContainsVals(3))
{
foapalrow3.Visible = true;
}
if(RowContainsVals(4))
{
foapalrow4.Visible = true;
}
if(RowContainsVals(5))
{
foapalrow5.Visible = true;
}
if(RowContainsVals(6))
{
foapalrow6.Visible = true;
}

。 。 。 // code elided for brevity
}
catch(Exception ex)
{
message.Text = String.Format(Exception occurred:{0},ex.Message) ;
}
}

private bool RowContainsVals(int rownum)
{
bool rowdirty = false;
switch(rownum)
{
case 3:
rowdirty =((!String.IsNullOrEmpty(boxFund2.Text))||
(!String.IsNullOrEmpty boxIndex2.Text))||
(!String.IsNullOrEmpty(boxOrganization2.Text))||
(!String.IsNullOrEmpty(boxAccount2.Text))||
(!String.IsNullOrEmpty (boxActivity2.Text))||
(!String.IsNullOrEmpty(boxAmount2.Text)));
break;
case 4:
rowdirty =((String.IsNullOrEmpty(boxFund3.Text))||
(!String.IsNullOrEmpty(boxIndex3.Text))||
String.IsNullOrEmpty(boxOrganization3.Text))||
(!String.IsNullOrEmpty(boxAccount3.Text))||
(!String.IsNullOrEmpty(boxActivity3.Text))||
!String.IsNullOrEmpty(boxAmount3.Text)));
break;
case 5:
rowdirty =((String.IsNullOrEmpty(boxFund4.Text))||
(!String.IsNullOrEmpty(boxIndex4.Text))||
String.IsNullOrEmpty(boxOrganization4.Text))||
(!String.IsNullOrEmpty(boxAccount4.Text))||
(!String.IsNullOrEmpty(boxActivity4.Text))||
!String.IsNullOrEmpty(boxAmount4.Text)));
break;
case 6:
rowdirty =((String.IsNullOrEmpty(boxFund5.Text))||
(!String.IsNullOrEmpty(boxIndex5.Text))||
String.IsNullOrEmpty(boxOrganization5.Text))||
(!String.IsNullOrEmpty(boxAccount5.Text))||
(!String.IsNullOrEmpty(boxActivity5.Text))||
!String.IsNullOrEmpty(boxAmount5.Text)));
break;
默认值:
rowdirty = false;
break;
}
return rowdirty;但是,这是我看到的代码之后运行:


}


那么,为什么将visible属性设置为visible不能将其设置为可见?



UPDATE



注意:如果我通过+按钮重新展开行,他们包含我添加到它们的值。所以行存活并保留他们的数据,他们只是不想显示自己...

解决方案

使用 Style [display] =table-row; 而不是 Visible = true; p>

你说通过设置风格 display:none,在后面的代码行中不可见。



注意,在asp.net中做一个control.Visible 是不一样的,使它看不见的样式。



Control.Visible = false 不会在客户端呈现HTML代码,而设置 display:none 将会使用隐藏浏览器上的行的样式呈现它。我认为这是你的情况,因为你说你隐藏和显示在客户端的行,为了做到他们必须存在于客户端,所以我假设在你的代码中没有地方他们是 Visible = false;


I have a table that has six rows, but starts off with only two of them visible (a header row and one "business" row).

The user can select a button that adds additional rows one at a time (actually, it just makes an existing row visible), up to a total of the six rows / five "business" rows.

Rows 2-6 are made invisible at first by this code-behind:

foapalrow3.Style["display"] = "none";

(with the same code for foapalrow4, foapalrow5, and foapalrow6).

They are then made visible via jQuery like so when the user selects the "+" button:

/* This makes the next hidden row visible, as long as there is one */
$(document).on("click", '[id$=btnAddFoapalRow]', function (e) {
    $('[id$=foapalhtmltable]').find('tr:hidden:first').show();
});

This works fine. The problem is, when the form is submitted, the previously visiblized rows revert back to being hidden (all but the first two). I'm trying to add code that will re-visiblize these rows if any text input in them was given a value. IOW, if I give the "Index" column a value in each row like so:

....I would hope that they would be made visible again, because they do have a value:

...and their visible property is indeed "true":

...but the rows remain recalcitrant, hiding in their burrows. This is the code behind for that:

private void btnSave_Click(object sender, EventArgs e)
{
    try
    {
        . . . // code elided for brevity
        ConditionallyCreateList();
        SaveInputToList();
        listOfListItems = ReadFromList();
        message.Text = "Saving the data has been successful";

        // Expose any rows with vals
        if (RowContainsVals(3))
        {
            foapalrow3.Visible = true;
        }
        if (RowContainsVals(4))
        {
            foapalrow4.Visible = true;
        }
        if (RowContainsVals(5))
        {
            foapalrow5.Visible = true;
        }
        if (RowContainsVals(6))
        {
            foapalrow6.Visible = true;
        }

        . . . // code elided for brevity
    }
    catch (Exception ex)
    {
        message.Text = String.Format("Exception occurred: {0}", ex.Message);
    }
}

private bool RowContainsVals(int rownum)
{
    bool rowdirty = false;
    switch (rownum)
    {
        case 3:
            rowdirty = ((!String.IsNullOrEmpty(boxFund2.Text)) ||
                (!String.IsNullOrEmpty(boxIndex2.Text)) ||
                (!String.IsNullOrEmpty(boxOrganization2.Text)) ||
                (!String.IsNullOrEmpty(boxAccount2.Text)) ||
                (!String.IsNullOrEmpty(boxActivity2.Text)) ||
                (!String.IsNullOrEmpty(boxAmount2.Text)));
            break;
        case 4:
            rowdirty = ((!String.IsNullOrEmpty(boxFund3.Text)) ||
                (!String.IsNullOrEmpty(boxIndex3.Text)) ||
                (!String.IsNullOrEmpty(boxOrganization3.Text)) ||
                (!String.IsNullOrEmpty(boxAccount3.Text)) ||
                (!String.IsNullOrEmpty(boxActivity3.Text)) ||
                (!String.IsNullOrEmpty(boxAmount3.Text)));
            break;
        case 5:
            rowdirty = ((!String.IsNullOrEmpty(boxFund4.Text)) ||
                (!String.IsNullOrEmpty(boxIndex4.Text)) ||
                (!String.IsNullOrEmpty(boxOrganization4.Text)) ||
                (!String.IsNullOrEmpty(boxAccount4.Text)) ||
                (!String.IsNullOrEmpty(boxActivity4.Text)) ||
                (!String.IsNullOrEmpty(boxAmount4.Text)));
            break;
        case 6:
            rowdirty = ((!String.IsNullOrEmpty(boxFund5.Text)) ||
                (!String.IsNullOrEmpty(boxIndex5.Text)) ||
                (!String.IsNullOrEmpty(boxOrganization5.Text)) ||
                (!String.IsNullOrEmpty(boxAccount5.Text)) ||
                (!String.IsNullOrEmpty(boxActivity5.Text)) ||
                (!String.IsNullOrEmpty(boxAmount5.Text)));
            break;
        default:
            rowdirty = false;
            break;
    }
    return rowdirty;
}

However, this is all I see after that code runs:

So why does setting the visible property to visible not indeed set them visible?

UPDATE

NOTE: If I re-expand the rows via the "+" button, they do contain the values I added to them. So the rows live and retain their data, they just don't want to show themselves...

解决方案

Try to change your code to use Style["display"] = "table-row"; instead of Visible = true;

You say that in code behind rows are made "invisible" by setting the style display:none.

Note that in asp.net making a control.Visible is NOT the same that making it invisible with an style.

Control.Visible = false will not render the HTML code on the Client Side while setting the display:none will do render it with an style that hides that rows on the browser. I assume this is yor case as you say that you hide and show the rows on the client side and in order to do that they must exist on the client side so I assume in no place in your code they are Visible = false;

这篇关于为什么我的行设置为可见后不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 07:54