首页 \ 问答 \ 在回发中选择保持单选按钮(keep radio button selected across postback)

在回发中选择保持单选按钮(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
更新时间:2022-09-09 06:09

最满意答案

问题似乎是调用了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.

相关问答

更多
  • 1. C++语言中try-catch 语句由一个 try 块后跟一个或多个 catch 子句构成,这些子句指定不同的异常处理程序。 2. try中的语句用于来放容易出错的代码,如果出错了它就不执行try下面的代码了,直接跳到catch里面去。如果没出异常则catch里面的代码不执行,它还有一个关键字finally它里面的代码无论有没有出异常它都要运行。 3. try-catch 的语句格式: try { //执行的代码,其中可能有异常。一旦发现异常,则立即跳到catch执行。否则不会执行catch里面的内容 ...
  • 您可能正在调用该函数并将结果分配给某些内容: 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 ...
  • 分割故障是访问不属于您的内存导致的特定类型的错误。它是一个帮助机制,可以防止内存损坏,并引入难以调试的内存错误。 每当你得到一个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 ...
  • 我想你想在第一次捕捉[ 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 ...
  • 问题似乎是调用了managed_shared_memory的析构函数,但是在try catch块之后你继续依赖它所持有的状态或分配。 managed_shared_memory segment; 回想一下,析构函数总是在作用域的末尾调用(基本上是任何结束} ),这也适用于try块。 如果这不是``main`函数,那么让异常转义给调用者(没有try catch)或者重新抛出它(或者另一个异常)可能会更好: try { managed_shared_memory segment(ope ...
  • ThreadState *state; state->mLimit = pLimit; 您正在写入您尚未分配的内存 ThreadState *state; state->mLimit = pLimit; You are writing to memory you haven't allocated
  • 在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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)