日期:2014-05-18  浏览次数:20472 次

GridView模板嵌套DropDownList+SqlDataSource的问题
<asp:GridView ID="GridView1" runat="server" Width="650px" AllowPaging="True" PageSize="5" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"> 
  <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
   
  <HeaderStyle BackColor="#404040" Font-Bold="True" Font-Names="Arial" ForeColor="White" 
  HorizontalAlign="Center" VerticalAlign="Middle" /> 
  <AlternatingRowStyle BackColor="Silver" /> 
  <Columns> 
  <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" 
  SortExpression="id" /> 
  <asp:TemplateField HeaderText="机型ID" SortExpression="MachineID"> 
  <EditItemTemplate> 
  <asp:DropDownList ID="TextBox1" DataSourceID="dsMachine" DataTextField="machinename" DataValueField="id" runat="server" > </asp:DropDownList> 
  <asp:SqlDataSource ID="dsMachine" runat="server" ConnectionString=" <%$ ConnectionStrings:ERPConnectionString %> " SelectCommand="SELECT [ID], [MachineName] FROM [Machines]"> </asp:SqlDataSource> 
  </EditItemTemplate> 
  <ItemTemplate> 
  <asp:Label ID="Label1" runat="server" Text=' <%# Bind("MachineID") %> '> </asp:Label> 
  </ItemTemplate> 
  </asp:TemplateField> 
  .................后面是一系列的模板列.. 
   
  <asp:CommandField HeaderText="编辑" ShowEditButton="True" ShowHeader="True" /> 
  <asp:ButtonField CommandName="Delete" HeaderText="删除" ShowHeader="True" Text="删除" /> 
  </Columns> 
   
  </asp:GridView> 


   
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:ERPConnectionString %> " 
  SelectCommand="uPCB_GetAllPCBRecord" SelectCommandType="StoredProcedure" UpdateCommand="uPCB_UpdatePCBRecord" UpdateCommandType="StoredProcedure"> 
&n