2012-08-30 59 views
0

结合我所发生的与SqlDataSource1绑定在的.aspx page.But当我使用事件“OnRowUpdating”,并与.An例外背后的代码更新一个GridView是更新在asp.net的GridView时的SqlDataSource

除非指定UpdateCommand,否则数据源'SqlDataSource1'不支持更新。

的GridView,我现在用的就是

<asp:GridView ID="gdvProfiles" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1" 
      OnRowUpdating="updateRecord" OnRowEditing="editRecord" OnRowCancelingEdit="cancelRecord" 
      AutoGenerateColumns="False" CellPadding="0" ForeColor="#333333" GridLines="None" 
      Style="margin-right: 38px" Font-Size="Small"> 

和OnRowUpdaing

protected void updateRecord(object sender, GridViewUpdateEventArgs e) 
    { 
     try 
     { 
      Label lblusername = gdvProfiles.Rows[e.RowIndex].FindControl("lblusername") as Label; 
      TextBox txtname = gdvProfiles.Rows[e.RowIndex].FindControl("txtname") as TextBox; 
      TextBox txtsponser = gdvProfiles.Rows[e.RowIndex].FindControl("txtsponser") as TextBox; 
      TextBox txtemail = gdvProfiles.Rows[e.RowIndex].FindControl("txtemail") as TextBox; 
      TextBox txtdob = gdvProfiles.Rows[e.RowIndex].FindControl("txtdob") as TextBox; 

      TextBox txthomecontact = gdvProfiles.Rows[e.RowIndex].FindControl("txthomecontact") as TextBox; 
      TextBox txtcontact = gdvProfiles.Rows[e.RowIndex].FindControl("txtcontact") as TextBox; 
      TextBox txtaddress = gdvProfiles.Rows[e.RowIndex].FindControl("txtaddress") as TextBox; 
      TextBox txtcity = gdvProfiles.Rows[e.RowIndex].FindControl("txtcity") as TextBox; 
      TextBox txtstate = gdvProfiles.Rows[e.RowIndex].FindControl("txtstate") as TextBox; 
      TextBox txtzipcode = gdvProfiles.Rows[e.RowIndex].FindControl("txtzipcode") as TextBox; 
      TextBox txtcountry = gdvProfiles.Rows[e.RowIndex].FindControl("txtcountry") as TextBox; 




      BORegistration oBORegistration = new BORegistration(); 
      BalRegistration oBalRegistration = new BalRegistration(); 
      oBORegistration.Name = lblusername.Text; 

      oBORegistration.Name = txtname.Text; 
      oBORegistration.Sponser = txtsponser.Text; 
      oBORegistration.Email = txtemail.Text; 
      oBORegistration.Dob = txtdob.Text; 

      oBORegistration.HomeContact = txthomecontact.Text; 
      oBORegistration.Contact = txtcontact.Text; 
      oBORegistration.Addressx = txtaddress.Text; 
      oBORegistration.City = txtcity.Text; 
      oBORegistration.State = txtstate.Text; 
      oBORegistration.ZipCode = txtzipcode.Text; 
      oBORegistration.Country = txtcountry.Text; 



      if (oBalRegistration.Updatememberprofile(oBORegistration)) 
      { 
       gdvProfiles.EditIndex = -1; 
       // FillData(); 
       gdvProfiles.DataBind(); 
      } 
     } 
     catch 
     { 
      throw; 
     } 
    } 

的SqlDataSounce是

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Universal %>" 
     ProviderName="System.Data.SqlClient" SelectCommand="spGetMemberProfile" SelectCommandType="StoredProcedure" 
     FilterExpression="Username LIKE '{0}%' OR Name LIKE '{0}%' OR   
     Sponser LIKE '{0}%' OR Email LIKE '{0}%' OR Dob LIKE '{0}%' OR 
     HomeContact LIKE '{0}%' OR Contact LIKE '{0}%' OR City LIKE '{0}%' OR 
     Statex LIKE '{0}%' OR ZipCode LIKE '{0}%' OR Country LIKE '{0}%' 
     "> 
     <FilterParameters> 
      <asp:ControlParameter Name="ID" ControlID="txtFilter" /> 
     </FilterParameters> 
    </asp:SqlDataSource> 
+1

您是否设置了数据源的UpdateCommand? –

+0

显示您的SqlDataSource1 aspx代码 –

+0

我在.cs页面上使用OnRowUpdaing事件 – ankit

回答

0

我在SqlDataSqouce做到了这一点被提及的UpdateCommand作为

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Universal %>" 
     ProviderName="System.Data.SqlClient" SelectCommand="spGetMemberProfile" UpdateCommand="spGetMemberProfile" 
     SelectCommandType="StoredProcedure" FilterExpression="Username LIKE '{0}%' OR Name LIKE '{0}%' OR   
     Sponser LIKE '{0}%' OR Email LIKE '{0}%' OR Dob LIKE '{0}%' OR 
     HomeContact LIKE '{0}%' OR Contact LIKE '{0}%' OR City LIKE '{0}%' OR 
     Statex LIKE '{0}%' OR ZipCode LIKE '{0}%' OR Country LIKE '{0}%' 
     "> 
     <FilterParameters> 
      <asp:ControlParameter Name="ID" ControlID="txtFilter" /> 
     </FilterParameters> 
    </asp:SqlDataSource>