1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / RAD GRID NOT UPDATEING!

RAD GRID NOT UPDATEING!

4 posts, 0 answered
  1. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    04 Mar 2010
    Link to this post
    Hi Guys ,
     Hope all of you are fine, I am in a bit of a weired situation here I am trying to use rad grid to update but it wont update any records
    here is the markup and the code that i used Hope it gives a clear picture.

    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="IndustryDataSource" 
        GridLines="None" Skin="WebBlue" 
        AutoGenerateColumns="False" 
        AllowPaging="True" EnableHeaderContextMenu="True" ShowFooter="True" 
        ShowStatusBar="True" DataMember="DefaultView" 
        oninsertcommand="RadGrid1_InsertCommand" 
        onupdatecommand="RadGrid1_UpdateCommand">
    <MasterTableView DataSourceID="IndustryDataSource" 
            DataKeyNames="Id" CommandItemDisplay="Top" DataMember="DefaultView">
    <RowIndicatorColumn>
    <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>
      
    <ExpandCollapseColumn>
    <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" 
                HeaderText="Id" SortExpression="Id" UniqueName="Id" ReadOnly="True" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" 
                HeaderText="Name" SortExpression="Name" 
                UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CreationDate" HeaderText="CreationDate" 
                SortExpression="CreationDate" UniqueName="CreationDate" 
                DataType="System.DateTime">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Ordering" HeaderText="Ordering" 
                SortExpression="Ordering" UniqueName="Ordering" 
                DataType="System.Int32">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ImageUrl" 
                HeaderText="ImageUrl" SortExpression="ImageUrl" 
                UniqueName="ImageUrl">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean" 
                HeaderText="IsActive" SortExpression="IsActive" 
                UniqueName="IsActive">
            </telerik:GridCheckBoxColumn>
            <telerik:GridEditCommandColumn AutoPostBackOnFilter="True">
            </telerik:GridEditCommandColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
    </telerik:RadGrid>

    the datasource markup is below...
    <asp:SqlDataSource ID="IndustryDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Sitefinity %>" 
        SelectCommand="SELECT * FROM [elx_Industry]">
    </asp:SqlDataSource>

    And The Cs Code for update command is...

    protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            throw new Exception("In Update command"); 
      
            //Get the GridEditableItem of the RadGrid
            GridEditableItem editedItem = e.Item as GridEditableItem;
      
      
            //Get The Primary Key
            string Id = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]
    ["Id"].ToString();
      
      
            string name = string.Empty;
            DateTime dt = DateTime.Now;
            int Ordering = 0;
            string ImageUrl = string.Empty;
            bool isactive = false;
      
            name = (editedItem["Name"].Controls[0] as TextBox).Text;
            dt = Convert.ToDateTime((editedItem["CreationDate"].Controls[0] as TextBox).Text);
            Ordering = Convert.ToInt32((editedItem["Ordering"].Controls[0] as TextBox).Text);
            ImageUrl = (editedItem["ImageUrl"].Controls[0] as TextBox).Text;
            isactive = (editedItem["IsActive"].Controls[0] as CheckBox).Checked;
      
            try
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString);
                SqlCommand com = con.CreateCommand();
      
      
                StringBuilder query = new StringBuilder();
                query.Append("UPDATE dbo.[elx_Industry]");
                query.Append("SET [Name]=@name");
                query.Append(",[CreationDate]=@dt");
                query.Append(",[Ordering]=@Ordering");
                query.Append(",[ImageUrl]=@ImageUrl");
                query.Append(",[IsActive]=@isactive");
                query.Append("WHERE [id]=@id");
      
                com.Parameters.AddWithValue("@id", Id);
                com.Parameters.AddWithValue("@name", name);
                com.Parameters.AddWithValue("@dt", dt);
                com.Parameters.AddWithValue("@Ordering", Ordering);
                com.Parameters.AddWithValue("@ImageUrl", ImageUrl);
                com.Parameters.AddWithValue("@isactive", isactive);
      
                com.CommandText = query.ToString();
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
                  
            }
            catch (Exception exp)
            {
                RadGrid1.Controls.Add(new LiteralControl("Unable to update Shippers. Reason: " +
    exp.Message));
                e.Canceled = true;
            }
        }

    Dont mind the exception i was just testing that the event gets fired or not.. but it doesnt get fired.
    I used the other approach of automatically deleting and updating but again data does not get effected.

    Any Help Would Really Be appreciated.

    Thanks
    Regards ,
    Adeel Arif.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    04 Mar 2010
    Link to this post
    Hello Adeel Arif,

    Thank you for using our services.

    Could you please try to subscribe to those commands in the code, on page load or initialize events for example. See sample bellow:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand);
        RadGrid1.DeleteCommand += new GridCommandEventHandler(RadGrid1_DeleteCommand);
        RadGrid1.InsertCommand += new GridCommandEventHandler(RadGrid1_InsertCommand);
    }


    All the best,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    04 Mar 2010
    Link to this post
    Hi Radoslav Georgiev ,

    It Didnt worked i subscribed for it but it seems that the event is'nt firing. When does actually it gets fired?, i added the edit command button from the property builder. and I have just started working on rad controls.... its kind of confusing for me i've downloaded the RAD controls documentation and this was the Shipper Example that i modified in to my own context but still stuck here.... Any idea what key point i am missing here aur what kind of mistake is there?

    Thanks
    Regards
    Adeel Arif.
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    04 Mar 2010
    Link to this post
    Hi Adeel Arif,

    Could you please take a look at the following blog post which samples how to Inesert/Detele/Update content items within Sitefinity: Insert/Update/Delete content items with RadGrid for ASP.NET AJAX.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered