Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET RadioButton是否在中继器中列出?_Asp.net_Repeater_Checkboxlist_Radiobuttonlist - Fatal编程技术网

ASP.NET RadioButton是否在中继器中列出?

ASP.NET RadioButton是否在中继器中列出?,asp.net,repeater,checkboxlist,radiobuttonlist,Asp.net,Repeater,Checkboxlist,Radiobuttonlist,aspx文件: <asp:Repeater ID="Repeater_sorular" runat="server"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <div class="div_soru"> <div class="div_soru_wrapper"> <%#Eval("S

aspx文件:

<asp:Repeater ID="Repeater_sorular" runat="server">
   <HeaderTemplate>
   </HeaderTemplate>
   <ItemTemplate>
      <div class="div_soru">
         <div class="div_soru_wrapper">
             <%#Eval("Subject")%>
             <asp:RadioButtonList ID="RadioButtonList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "1" %>'
                DataSource='<%#Eval("Secenekler")%>' DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'>
             </asp:RadioButtonList>
             <asp:CheckBoxList ID="CheckBoxList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "2" %>'
                DataSource='<%#Eval("Secenekler")%>' DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'>
             </asp:CheckBoxList>
         </div>
      </div>
   </ItemTemplate>
   <FooterTemplate>
   </FooterTemplate>
</asp:Repeater>
我的问题是:

我无法绑定datavaluefield和DataTextField。如果我按照上面的定义写作。我犯了这个错误

DataBinding: '<>f__AnonymousType1`8[[System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.IEnumerable`1[[<>f__AnonymousT...' does not contain a property with the name 'OptionName'.
DataBinding:'f_uanonymoustype1`8[[System.Nullable`1[[System.Int32,mscorlib,Version=2.0.0.0,Culture=中立,PublicKeyToken=b77a561934e089]],mscorlib,Version=2.0.0.0,Culture=中立,PublicKeyToken=b77a561934e089],[System.String,mscorlib,Version=2.0.0.0,Culture=中立,PublicKeyToken=b77a56934e089],[System.Int32,mscorlib,版本=2.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Int32,mscorlib,版本=2.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089],[System.Nullable`1][[System.Int32,mscorlib,版本=2.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089]],mscorlib,版本=2.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089],[System.String,mscorlib,版本=2.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089],[System.String,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.IEnumerable`1[[f_uAnonymousut…]不包含名为“OptionName”的属性。
如何绑定值和文本


谢谢。

错误解释得很清楚:

does not contain a property with the name 'OptionName'
只需更改此项(在
RadioButtonList
复选框列表的声明中):

就这样,您不需要计算绑定,只需指定属性的名称即可。其余代码看起来不错

编辑 根据请求,要从
RadioButtonList
中获取所选项目:

DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'
<asp:GridView runat="server" OnRowCommand="grdProducts_RowCommand" ID="grdProducts">
    <Columns>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" 
                    CommandName="myLink" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' Text="Button"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:RadioButtonList DataTextField="NestedValue" DataValueField="ID" runat="server" DataSource='<%# Eval("Nested") %>' ID="radios">
                </asp:RadioButtonList>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<asp:Label runat="server" ID="lblMessage" />

代码隐藏:

    protected void grdProducts_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "myLink":
                var row = this.grdProducts.Rows[int.Parse(e.CommandArgument.ToString())];
                var radios = row.FindControl("radios") as RadioButtonList;
                this.lblMessage.Text += "<br/>" + radios.UniqueID;
                this.lblMessage.Text += "<br/> dedede " + radios.SelectedValue;
                break;
        }
    }
protectedvoid grdProducts\u行命令(对象发送方,GridViewCommandEventArgs e)
{
开关(例如CommandName)
{
案例“myLink”:
var row=this.grdProducts.Rows[int.Parse(e.CommandArgument.ToString())];
var radios=行。FindControl(“radios”)作为RadioButtonList;
this.lblMessage.Text+=“
”+radios.UniqueID; this.lblMessage.Text+=“
dedede”+radios.SelectedValue; 打破 } }
我想问另一个问题。那么,我可以获取这些listitems的值吗?你能给我一个关于这一点的起点吗?可能是一个链接等。谢谢。谢谢你的回答。但是我想通过一个提交按钮获取所有值。你能看看这个吗:
<asp:GridView runat="server" OnRowCommand="grdProducts_RowCommand" ID="grdProducts">
    <Columns>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" 
                    CommandName="myLink" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' Text="Button"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:RadioButtonList DataTextField="NestedValue" DataValueField="ID" runat="server" DataSource='<%# Eval("Nested") %>' ID="radios">
                </asp:RadioButtonList>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<asp:Label runat="server" ID="lblMessage" />
    protected void grdProducts_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "myLink":
                var row = this.grdProducts.Rows[int.Parse(e.CommandArgument.ToString())];
                var radios = row.FindControl("radios") as RadioButtonList;
                this.lblMessage.Text += "<br/>" + radios.UniqueID;
                this.lblMessage.Text += "<br/> dedede " + radios.SelectedValue;
                break;
        }
    }