gridview with radiobuttonlist模板字段

时间:2011-05-28 09:54:49

标签: asp.net sql data-binding gridview

我创建了一个带有单选按钮列表的gridview。它会抛出错误,如

RadioButtonList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

这是我在gridview

中绑定的编码
q = "SELECT 
        s.rollno,
        s.studname,
        d.deptname,
        ct.ctype,
        c.course,
        s.status 
    FROM
        dbmasdeptcreat d,
        dbmascoursetypecreat ct,
        dbmascoursecreat c,
        dbmasstuddet s 
    WHERE 
        s.deptid=d.deptid AND 
        s.ctypeid=ct.ctypeid AND 
        s.cid=c.cid AND 
        s.status <> 'ACTIVE' AND 
        s.collname='" & lablcollname.Text & "'"

        ds = c1.getDataset(q)
        GridView2.DataSource = ds
        GridView2.DataBind()
        GridView2.Visible = True

这是我的gridview源编码

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
        <asp:CommandField HeaderText="Edit" ShowEditButton="True" ShowHeader="True" />
        <asp:BoundField DataField="rollno" HeaderText="Rollno" ReadOnly="True" />
        <asp:BoundField DataField="studname" HeaderText="Student Name" ReadOnly="True" />
        <asp:BoundField DataField="deptname" HeaderText="Department " ReadOnly="True" />
        <asp:BoundField DataField="course" HeaderText="Course Type" ReadOnly="True" />
        <asp:BoundField DataField="course" HeaderText="Course" ReadOnly="True" />
        <asp:TemplateField HeaderText="Status">
            <EditItemTemplate>
                <asp:RadioButtonList ID="RadioButtonList2" runat="server" Text='<%# Bind("status") %>' >
                    <asp:ListItem>GUEST</asp:ListItem>
                    <asp:ListItem>REGULAR</asp:ListItem>
                </asp:RadioButtonList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("status") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#E9E7E2" />
    <SortedAscendingHeaderStyle BackColor="#506C8C" />
    <SortedDescendingCellStyle BackColor="#FFFDF8" />
    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>

1 个答案:

答案 0 :(得分:0)

我认为你没有正确附加你的代码,请再次附上它,你是否用某种数据源如SQL数据源填充那个单选按钮列表?因为当数据源中的值与您为单选按钮列表定义的值集合中的任何值不匹配时,通常会发生此类错误,例如,如果您定义了类似

的值
Apple
Orange
Banana

对于单选按钮列表和数据源返回Mango然后单选按钮列表将抛出此类错误,因为它无法选择Mango,因为它在其定义的集合中不可用。

如果您提供代码,我可以帮助您更好。