This is a migrated thread and some comments may be shown as answers.

[Solved] Getting the items from template

11 Answers 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jebamalai
Top achievements
Rank 1
Jebamalai asked on 26 Jun 2008, 06:15 AM
Dear All,

I am new to Telerik grid.

I have created a custom template for editing the items.

When I clicked on the "Update" button the Item_Updated event is not triggered.

I referred the sample given in the live demos.

I am unable to get the items in the edit template, it is giving the old values not the edited values,  how can I get the edited values?

I also referred the below link:
http://www.telerik.com/help/aspnet-ajax/grdcustomeditforms.html


Thanks a lot in advance.

Best Regards,
M. J. Jaya Chitra.

11 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Jun 2008, 07:23 AM
Hi Jaya,

You can get the edited or updated values in the UpdateCommand event as shown in the code snippet below.

ASPX:
 
 
<EditFormSettings> 
            <FormTemplate> 
                <asp:TextBox ID="TextBox1" Text='<%#Eval("ToandFro") %>' runat="server"></asp:TextBox> 
                <asp:TextBox ID="TextBox2" Text='<%#Eval("FirstName") %>' runat="server"></asp:TextBox> 
                <asp:LinkButton ID="LinkButton1" Text="Update" CommandName="Update" runat="server"></asp:LinkButton> 
                <asp:LinkButton ID="LinkButton2" Text="Cancel" CommandName="Cancel" runat="server"></asp:LinkButton> 
            </FormTemplate> 
</EditFormSettings> 

CS:
 protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem item = (GridEditFormItem)e.Item; 
            TextBox txt = (TextBox)item.FindControl("TextBox2"); 
            string strtxt = txt.Text.ToString(); 
        } 
    } 

Thanks
Princy.



0
Jebamalai
Top achievements
Rank 1
answered on 26 Jun 2008, 07:28 AM
Dear Princy,

Thanks a lot for your valuable support and timely response.

I have fixed the issue.

Best Regards,

M. J. Jaya Chitra.
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2008, 07:44 AM
Hi Jaya,

You can also go through the following help articles.

Updating values using UserControl/FormTemplate
Accessing cells and rows

Shinu.
0
Jebamalai
Top achievements
Rank 1
answered on 26 Jun 2008, 09:09 AM
Dear Shinu / Princy,

In my edit template I have bounded a dropdown list as follows:

<asp:DropDownList ID="ddlCountry" runat="server" DataTextField="CountryName" DataValueField="CountryCode"
DataSourceID="CountryList" SelectedValue='<%# Bind("CountryCode")%>'>
<asp:ListItem Text="Select" Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
When I am clicking on "Edit" it is working fine but while clicking on "Add" it is giving the following error:
"ddlCountry has a SelectedValue which is invalid becuase it does not exist in the list of items.  Parameter name: value".
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Jun 2008, 09:42 AM
Hi Jaya,

The reason for this error is that your grid instance can not bind a value for the newly inserted item through the Eval()/Bind() syntax you hard-coded (as you may have seen from the stack trace of the error).
 Go through the following help article which explains how to fix this problem.
Known reasons for error messages

Princy.
0
Jebamalai
Top achievements
Rank 1
answered on 26 Jun 2008, 09:49 AM
Dear Princy,

Thank you for your reply.

It is useful, but I have fixed the issue as follows:

<asp:DropDownList ID="ddlCountry" runat="server" DataTextField="CountryName" DataValueField="CountryCode"   DataSourceID="CountryList" SelectedValue='<%# (Container is GridEditFormInsertItem) ? 1 : Eval("CountryCode") %>'>
</asp:DropDownList>

If this is wrong, kindly let me know the same.


0
Jebamalai
Top achievements
Rank 1
answered on 26 Jun 2008, 10:55 AM
Dear Princy / Shinu,

I have an issue while inserting the records.

In the Item_Command event I am checking whether the command name is a "RadGrid.UpdateCommandName", then I am updating and clearing the editindexes by using:
RadGrid1.EditIndexes.Clear();
The edit item is cleared and it is not displayed.

But while insetting the record, the edit index is zero and it is not clearing the edit template and it is still there after inserting also.

Can you help in this regard?


Thanks a lot in advance.

0
Princy
Top achievements
Rank 2
answered on 27 Jun 2008, 04:03 AM
Hi Jaya,

Try the following line of code to close the Insert form after performing the  insert operation.

CS:
protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        //code for insert 
        //..... 
        // Close the Insert form 
        RadGrid1.MasterTableView.IsItemInserted = false
    } 


Thanks
Princy.
0
Jebamalai
Top achievements
Rank 1
answered on 27 Jun 2008, 04:40 AM
Dear Princy,

Based on your suggestion I have tried it, it is giving the error "Insert item is available only when the grid is in insert mode.

Do I need to write any code to make this?


0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Jun 2008, 05:53 AM
Hi Jaya Chitra,

Have you set AllowAutomaticInserts to true? Try setting it to false in the aspx as shown below.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  AllowAutomaticInserts="false" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" > 


Thanks
Shinu
0
Jebamalai
Top achievements
Rank 1
answered on 27 Jun 2008, 06:11 AM
Dear Shinu / Princy,

Thanks a lot for your valuable and timely support.

I have fixed the issue.

Best Regards,

M. J. Jaya Chitra

Tags
Grid
Asked by
Jebamalai
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jebamalai
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or