数据列表中单选按钮上的评估 ID

发布于 2024-08-11 09:17:41 字数 3102 浏览 6 评论 0原文

我的代码需要带有单选按钮的数据列表,并且 iv 使其成为单一可选择的 onitemdatabound...现在我尝试根据选定的单选按钮评估隐藏字段

我的代码就像

后面的aspx 代码

<asp:DataList ID="DataList1" runat="server" RepeatColumns = "4"  CssClass="datalist1" 
                RepeatLayout = "Table"  OnItemDataBound="SOMENAMEItemBound"
                CellSpacing="20" onselectedindexchanged="DataList1_SelectedIndexChanged">
                <ItemTemplate>
                <br />
                <table cellpadding = "5px" cellspacing = "0" class="dlTable">
                <tr>
                <td align="center">
                <a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>' 
                Width = "100px" Height = "100px" style ="cursor:pointer" />
                </td>            
                </tr>
                <tr >
                <td align="center">                    
                <asp:RadioButton ID="rdb" runat="server"  OnCheckedChanged="rdb_click" AutoPostBack="True" />            
                <asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' /> 
                </td>
                </tr>                     
                </table>

 </ItemTemplate> 
</asp:DataList>

代码

 protected void SOMENAMEItemBound(object sender, DataListItemEventArgs e)
        {
            RadioButton rdb;
            rdb = (RadioButton)e.Item.FindControl("rdb");
            if (rdb != null)
                rdb.Attributes.Add("onclick", "CheckOnes(this);");



        }

  protected void rdb_click(object sender, EventArgs e)
        {
            for (int i = 0; i < DataList1.Items.Count; i++)
            {
                RadioButton rdb;
                rdb = (RadioButton)DataList1.Items[i].FindControl("rdb");
                if (rdb != null)
                {
                    if (rdb.Checked)
                    {
                        HiddenField hf = (HiddenField)DataList1.Items[i].FindControl("HiddenField1");
                        Response.Write(hf.Value);
                    }

                }
            }
        }

JavaScript

function CheckOnes(spanChk){


var oItem = spanChk.children;
var theBox= (spanChk.type=="radio") ?
spanChk : spanChk.children.item[0];

xState=theBox.unchecked;
elm=theBox.form.elements;

for(i=0;i<elm.length;i++)
if(elm[i].type=="radio" &&
elm[i].id!=theBox.id)
{
elm[i].checked=xState;
}
}

我使用...我正在获取像这样的错误

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'pload Demonstration|'.

有没有其他方法可以做到这一点或者任何人都可以帮助摆脱这个问题

my code gota datalist with radio button and iv made it single selectable onitemdatabound....now im trying to evaluate a hiddenfield on basis of selected radio button

my code goes like this

aspx code

<asp:DataList ID="DataList1" runat="server" RepeatColumns = "4"  CssClass="datalist1" 
                RepeatLayout = "Table"  OnItemDataBound="SOMENAMEItemBound"
                CellSpacing="20" onselectedindexchanged="DataList1_SelectedIndexChanged">
                <ItemTemplate>
                <br />
                <table cellpadding = "5px" cellspacing = "0" class="dlTable">
                <tr>
                <td align="center">
                <a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>' 
                Width = "100px" Height = "100px" style ="cursor:pointer" />
                </td>            
                </tr>
                <tr >
                <td align="center">                    
                <asp:RadioButton ID="rdb" runat="server"  OnCheckedChanged="rdb_click" AutoPostBack="True" />            
                <asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' /> 
                </td>
                </tr>                     
                </table>

 </ItemTemplate> 
</asp:DataList>

code behind

 protected void SOMENAMEItemBound(object sender, DataListItemEventArgs e)
        {
            RadioButton rdb;
            rdb = (RadioButton)e.Item.FindControl("rdb");
            if (rdb != null)
                rdb.Attributes.Add("onclick", "CheckOnes(this);");



        }

  protected void rdb_click(object sender, EventArgs e)
        {
            for (int i = 0; i < DataList1.Items.Count; i++)
            {
                RadioButton rdb;
                rdb = (RadioButton)DataList1.Items[i].FindControl("rdb");
                if (rdb != null)
                {
                    if (rdb.Checked)
                    {
                        HiddenField hf = (HiddenField)DataList1.Items[i].FindControl("HiddenField1");
                        Response.Write(hf.Value);
                    }

                }
            }
        }

the javascript im using...

function CheckOnes(spanChk){


var oItem = spanChk.children;
var theBox= (spanChk.type=="radio") ?
spanChk : spanChk.children.item[0];

xState=theBox.unchecked;
elm=theBox.form.elements;

for(i=0;i<elm.length;i++)
if(elm[i].type=="radio" &&
elm[i].id!=theBox.id)
{
elm[i].checked=xState;
}
}

iam getting an error like this

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'pload Demonstration|'.

is there any other way to do this or can nyone plz help to get rid of this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在深巷 2024-08-18 09:17:42

问题可能是您的 Response.Write() 调用。看看 此博文。它概述了出现此特定异常的原因以及如何防止它。另请查看此 StackOverflow 线程

The problem is probably your Response.Write() call. Take a look at this blog post. It outlines the reasons why this particular exception shows up, and how to prevent it. Also take a look at this StackOverflow thread.

鼻尖触碰 2024-08-18 09:17:42

好吧,让我们删除响应写入...现在我的代码隐藏中有以下内容...其余部分

label5.text=hf.value.ToString();

现在相同,当我使用更新面板和嵌套更新面板时,我可以评估标签,就像这样,

<asp:UpdatePanel ID="UpdatePanel9" runat="server" >
                <ContentTemplate>

                <asp:DataList ID="DataList1" runat="server" RepeatColumns = "4"  
                        CssClass="datalist1"  OnItemDataBound="SOMENAMEItemBound"
                CellSpacing="10" onselectedindexchanged="DataList1_SelectedIndexChanged" 
                        HorizontalAlign="Center" Width="500px">
                <ItemTemplate>
                <br />
                <table cellpadding = "5px" cellspacing = "0" class="dlTable">
                <tr>
                <td align="center">
                <a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>' 
                Width = "100px" Height = "100px" style ="cursor:pointer" />
                </td>            
                </tr>
                <tr >
                <td align="center"> 
                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                    <Triggers>
                   <asp:PostBackTrigger ControlID="rdb" />
                    </Triggers>
                          <ContentTemplate>          
                <asp:RadioButton ID="rdb" runat="server"  OnCheckedChanged="rdb_click" AutoPostBack="true"  /> 

                 </ContentTemplate> 
                </asp:UpdatePanel>

                <asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' /> 
                </td>
                </tr>                     
                </table>

 </ItemTemplate> 

</asp:DataList>


         </ContentTemplate>
         </asp:UpdatePanel>

有没有一种方法可以在不完整的情况下完成此操作页面回发....asyncpostback 触发器似乎不起作用

Okey lets just remove response write...now i have following in my codebehind...rest is same

label5.text=hf.value.ToString();

now i am able to evaluate Label when i use update panel nd nested updatepanel like this

<asp:UpdatePanel ID="UpdatePanel9" runat="server" >
                <ContentTemplate>

                <asp:DataList ID="DataList1" runat="server" RepeatColumns = "4"  
                        CssClass="datalist1"  OnItemDataBound="SOMENAMEItemBound"
                CellSpacing="10" onselectedindexchanged="DataList1_SelectedIndexChanged" 
                        HorizontalAlign="Center" Width="500px">
                <ItemTemplate>
                <br />
                <table cellpadding = "5px" cellspacing = "0" class="dlTable">
                <tr>
                <td align="center">
                <a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>' 
                Width = "100px" Height = "100px" style ="cursor:pointer" />
                </td>            
                </tr>
                <tr >
                <td align="center"> 
                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                    <Triggers>
                   <asp:PostBackTrigger ControlID="rdb" />
                    </Triggers>
                          <ContentTemplate>          
                <asp:RadioButton ID="rdb" runat="server"  OnCheckedChanged="rdb_click" AutoPostBack="true"  /> 

                 </ContentTemplate> 
                </asp:UpdatePanel>

                <asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' /> 
                </td>
                </tr>                     
                </table>

 </ItemTemplate> 

</asp:DataList>


         </ContentTemplate>
         </asp:UpdatePanel>

is there a way to to get this done without full page postback....asyncpostback trigger doesnt seem to work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文