关于GridView绑定XML数据源,请高手指点,多谢。
我使用GridView控件绑定了xml数据源,运行后可以读取xml数据,但checkbox控件不能选择。
xml:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<NODE1 checkbox2="false" id="01" name="项目" checkbox1="true"> </NODE1>
<step checkbox2="false" id="01101" name="审批" checkbox1="true"></step>
<NODE2 checkbox2="false" id="02" name="评审招标" checkbox1="true"></NODE2>
</root>
绑定xml代码:
<asp:GridView ID="GridView1" runat="server"
DataSourceID="XmlDataSource1"
Width="445px" onselectedindexchanged="GridView1_SelectedIndexChanged"
AutoGenerateColumns="false" onrowdatabound="GridView1_RowDataBound"
onrowediting="GridView1_RowEditing" DataKeyNames="id,name">
<Columns >
<asp:CheckBoxField DataField="checkbox2" HeaderText="步骤选择" SortExpression="是否选择" ReadOnly="false"/>
<asp:BoundField DataField="id" HeaderText="流程编号" SortExpression="id" ReadOnly="false" />
<asp:BoundField DataField="name" HeaderText="步骤名称" SortExpression="name" ReadOnly="false" />
<asp:CheckBoxField DataField="checkbox1" HeaderText="是否审批"
SortExpression="是否审批" ReadOnly="false" />
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/Configs/XMLFile1.xml"></asp:XmlDataSource>
[解决办法]
改用模板字段:
<asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1" Width="445px" AutoGenerateColumns="False" DataKeyNames="id,name"> <Columns> <asp:TemplateField HeaderText="步骤选择" SortExpression="是否选择"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="id" HeaderText="流程编号" SortExpression="id" ReadOnly="false" /> <asp:BoundField DataField="name" HeaderText="步骤名称" SortExpression="name" ReadOnly="false" /> <asp:CheckBoxField DataField="checkbox1" HeaderText="是否审批" SortExpression="是否审批" ReadOnly="false" /> </Columns> </asp:GridView>