当前位置:编程学习 > C#/ASP.NET >>

在GrideView中,怎样用DataSource绑定的数据的方式启动编辑?

在GrideView中,我用户ItemTemplate模板和EditItemTemplate模板来布局用SqlDataSouce绑定数据点击编辑就可以编辑内容了,但用DataSource来绑定就不行了?代码如下
用SqlDataSouce绑定
 <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowEditing="GridView1_RowEditing" DataSourceID="SqlDataSource1" AutoGenerateColumns="False">
<Columns>
             <asp:TemplateField HeaderText="编号">
               <ItemTemplate>
                 <asp:Label ID="lblstuId" runat="server" Text='<%#Eval("stuID") %>'></asp:Label>
               </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField>
               <HeaderTemplate>
                  <asp:Label ID="lblstuNameTitle" runat="server" Text="姓名"></asp:Label>
               </HeaderTemplate>
               <ItemTemplate>
                 <asp:Label ID="lblstuName" runat="server" Text='<%#Eval("stuName") %>'></asp:Label>
               </ItemTemplate>
               <EditItemTemplate>
                 <asp:TextBox ID="txtName" runat="server" Text='<%#Eval("stuName") %>' Width="50"></asp:TextBox>
               </EditItemTemplate>
             </asp:TemplateField>
<asp:TemplateField  HeaderText="编辑">
                 <ItemTemplate>
                   <asp:LinkButton ID="edit1" CommandName="edit" runat="server" Text="编辑"></asp:LinkButton>
                 </ItemTemplate>
                 <EditItemTemplate>
                   <asp:LinkButton ID="cancel1" CommandName="cancel" runat="server" Text="取消"></asp:LinkButton>
                 </EditItemTemplate>
              </asp:TemplateField>
</columns>
 </asp:GridView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:schollConnectionString %>"
            SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
用dataSource绑定:
this.GridView1.DataSource = this.GetData().Tables[0].DefaultView;
 this.GridView1.DataBind();
请内为高手解决一下,谢谢!
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,