在回发中选择保持单选按钮(keep radio button selected across postback)
我有一个带有单选按钮的gridview来选择一行。 gridview根据从下拉列表中选择的值从SQL DB填充。 我想要做的是当用户移动到不同的类别时保持选中的单选按钮,因此如果他想通过DDL返回,则仍然选择之前选择的值。
做这个的最好方式是什么? 应用程序将有用户,我有阅读会话可以帮助我,但我不知道它是如何工作的!
提前致谢
I have a gridview with radio buttons to select a single row. The gridview is populated from a SQL DB according to a value selected from a drop down list. What I want to do is keep the selected radio button when the user moves to a different category, so if he wants to move back via the DDL the value he selected previously is still selected.
What is the best way to do this? The application will have users and I have read sessions could help me with this but I have no idea how it works!
Thanks in advance
原文:https://stackoverflow.com/questions/17467128
最满意答案
问题似乎是调用了
managed_shared_memory
的析构函数,但是在try catch块之后你继续依赖它所持有的状态或分配。managed_shared_memory segment;
回想一下,析构函数总是在作用域的末尾调用(基本上是任何结束
}
),这也适用于try块。如果这不是``main`函数,那么让异常转义给调用者(没有try catch)或者重新抛出它(或者另一个异常)可能会更好:
try { managed_shared_memory segment(open_only, "MySharedMemory"); res=segment.find<MyType>("MyType instance"); cout<<"Child: Segment of length "<<res.second<<" is found at "<<res.first<<endl; cout<<"Child: "<<res.first->first<<", "<<res.first->second<<endl; } catch (interprocess_exception &e) { cerr<<"Error while opening the segment"<<endl; throw; }
确实,看看文档
托管内存段最重要的服务是:
动态分配内存部分的段。
在内存段中构造C ++对象。 这些对象可以是匿名的,也可以将名称与它们关联起来。
搜索命名对象的功能。
自定义许多功能:内存分配算法,索引类型或字符类型。
原子构造和析构,以便如果在两个进程之间共享段,则无法创建两个对象
与同名相关联,简化了同步。The problem seems to be that the destructor of
managed_shared_memory
is called, but you continue to rely on state or allocation held by it after the try catch block.managed_shared_memory segment;
Recall that destructors are always called at the end of a scope (basically any closing
}
), and this goes for try blocks as well.If this was not the ``main` function, it would likely be better to let the exception escape to the caller (no try catch), or re-throw it (or another exception):
try { managed_shared_memory segment(open_only, "MySharedMemory"); res=segment.find<MyType>("MyType instance"); cout<<"Child: Segment of length "<<res.second<<" is found at "<<res.first<<endl; cout<<"Child: "<<res.first->first<<", "<<res.first->second<<endl; } catch (interprocess_exception &e) { cerr<<"Error while opening the segment"<<endl; throw; }
Indeed, have a look at the documentation
The most important services of a managed memory segment are:
Dynamic allocation of portions of a memory the segment.
Construction of C++ objects in the memory segment. These objects can be anonymous or we can associate a name to them.
Searching capabilities for named objects.
Customization of many features: memory allocation algorithm, index types or character types.
Atomic constructions and destructions so that if the segment is shared between two processes it's impossible to create two objects
associated with the same name, simplifying synchronization.
相关问答
更多-
C++如何使用try-catch[2023-07-06]
1. C++语言中try-catch 语句由一个 try 块后跟一个或多个 catch 子句构成,这些子句指定不同的异常处理程序。 2. try中的语句用于来放容易出错的代码,如果出错了它就不执行try下面的代码了,直接跳到catch里面去。如果没出异常则catch里面的代码不执行,它还有一个关键字finally它里面的代码无论有没有出异常它都要运行。 3. try-catch 的语句格式: try { //执行的代码,其中可能有异常。一旦发现异常,则立即跳到catch执行。否则不会执行catch里面的内容 ... -
C ++分段错误(C++ segmentation fault)[2023-07-06]
您可能正在调用该函数并将结果分配给某些内容: Polynomial p = ....; std::string s = p.toString(); 由于Polynomial::toString()没有return语句,这本身就是未定义的行为,因此很容易导致分段违规。 你可以通过返回stringstreams的`字符串来轻松解决这个问题: return result.str(); You are probably calling the function and assigning the result ... -
在Linux上,我们也可以将它们作为例外。 通常,当程序执行分段故障时,会发送一个SIGSEGV信号。 您可以为此信号设置自己的处理程序,并减轻后果。 当然,你应该确实可以从这种情况中恢复过来。 在你的情况下,我想,你应该调试你的代码。 回到主题 我最近遇到一个将这种信号转换为异常的库 ( 简短手册 ),因此可以编写如下代码: try { *(int*) 0 = 0; } catch (std::exception& e) { std::cerr << "Exception catched ...
-
什么是分割错误?(What is a segmentation fault?)[2022-02-14]
分割故障是访问不属于您的内存导致的特定类型的错误。它是一个帮助机制,可以防止内存损坏,并引入难以调试的内存错误。 每当你得到一个segfault,你知道你正在做错误的内存 - 访问已经释放的变量,写入内存的只读部分等。分割错误在大多数语言中基本上是一样的,让你混乱在内存管理中,C和C ++中的segfaults没有任何区别。 有很多方法可以得到一个segfault,至少在较低级别的语言,如C(++)。 获取segfault的常见方法是取消引用空指针: int *p = NULL; *p = 1; 当您尝试 ... -
似乎以下行返回null XMLElement *pStartTimeStamp = pRoot->FirstChildElement("mobileDevice")->FirstChildElement("RealTimeInformation"); gdb输出显示“this”指针为空,这一点很明显。 It seems that the following line is returning a null XMLElement *pStartTimeStamp = pRoot->FirstChildEle ...
-
关于try-catch的问题(question about try-catch)[2024-05-06]
我想你想在第一次捕捉[ catch (Exception e) ]后关闭你的溪流finally使用: try { // Do foo with is and db } catch (Exception e) { // Do bar for exception handling } finally { try { is.close(); db.close(); } catch (Exception e2) { // gah! ... -
在Database::add的else子句中,不设置t->link = NULL ,因此它未初始化。 您应该为初始化其成员的data添加构造函数,或者使用value-initializing new来确保正确初始化所有内容: t = new data(); // note the parentheses In the else clause in Database::add, you do not set t->link = NULL, so it is uninitialized. You should ...
-
如果引入了try-catch,则会出现C ++ Segmentation错误(C++ Segmentation fault if try-catch is introduced)[2023-04-06]
问题似乎是调用了managed_shared_memory的析构函数,但是在try catch块之后你继续依赖它所持有的状态或分配。 managed_shared_memory segment; 回想一下,析构函数总是在作用域的末尾调用(基本上是任何结束} ),这也适用于try块。 如果这不是``main`函数,那么让异常转义给调用者(没有try catch)或者重新抛出它(或者另一个异常)可能会更好: try { managed_shared_memory segment(ope ... -
C ++线程中的分段错误(Segmentation fault in C++ thread)[2022-11-01]
ThreadState *state; state->mLimit = pLimit; 您正在写入您尚未分配的内存 ThreadState *state; state->mLimit = pLimit; You are writing to memory you haven't allocated -
C中的try-catch语句(try-catch statement in C)[2023-06-20]
在C中有一个try-catch语句吗? 还是有人制作的外部图书馆? 会非常有用 在Windows上有SEH,但你真的不应该使用它来用于一般应用程序。 没有类似C ++析构函数的东西,就不可能编写真正的异常安全代码。 如果没有,有没有办法可以确定变量是否是一个数组? 是。 你自己跟踪它。 is there a try-catch statement in C? or an external library someone made? would be very useful On Windows there ...