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

[Solved] Extracting values from editable grid template column

2 Answers 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elena
Top achievements
Rank 1
Elena asked on 05 Aug 2009, 07:57 PM
I have a simple grid with template column:

<

 

telerik:GridTemplateColumn HeaderText="Notification" UniqueName="TemplateColumn"

 

 

 

EditFormColumnIndex="1" ReadOnly="false">

 

 

 

<ItemTemplate>

 

 

<%

# Eval("vchNewsText") %>

 

 

 

</ItemTemplate>

 

 

 

 

<EditItemTemplate>

 

 

 

<span><telerik:RadTextBox runat="server" ID="txtNotification" Width="750px" height="200px"

 

 

 

TextMode="MultiLine"

 

 

 

Text='<%# Bind("vchNewsText") %>'></telerik:RadTextBox><span></span>

 

 

 

</EditItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

</Columns>

 

 

 


User is supposed to add a new row and fill in the vchNewsText field.

In Grid_ItemCommand procedure I am  trying to extract new value from txtNotification TextBox in order to update
dataset. 

s1 = (editedItem.FindControl(

"txtNotification") as TextBox).Text;

 

 


Result-control not found 

Another try was:

 

Hashtable newValues = new Hashtable();

 

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
s1=(string)newValues["TemplateColumn"];

Result-empty string;

So how do I extract the new value of Control in Template Column in Grid_ItemCommand procedure ?

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Aug 2009, 06:40 AM
Hello Elena,

I suppose you want to access the textbox after the user has entered some text inorder to add a new row to the grid. If thats the case then you would have to access the insert item and not the edit item.
If you are using 'InPlace' EditMode then try out the following code:
c#:
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "InsertCommand"
        { 
            GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; 
            string s1 = (insertItem.FindControl("txtNotification"as TextBox).Text; 
             
        } 
    } 

or else if you are using 'EditForms' EditMode then try out the following code:
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
       if (e.CommandName == "InsertCommand"
        { 
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item; 
            string s1 = (insertItem.FindControl("txtNotification"as TextBox).Text; 
             
        } 
    } 

Thanks
Princy.
0
Elena
Top achievements
Rank 1
answered on 06 Aug 2009, 02:12 PM
Princy,It did not help. s1 string comes empty.
And e.Item.ItemType ahows like EditItem.

Here is proc text:

 

if

 

(e.CommandName == "PerformInsert")

 

{

 

 

DataTable dsAlertTable = (DataTable)Session["dsAlertTable"];

 

 

DataRow newRow = dsAlertTable.NewRow();

 

 

 

 

// s1 = (editedItem.FindControl("txtNotification") as TextBox).Text;

 

 

 

 

 

 

GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;

 

 

 

string s1 = (insertItem.FindControl("txtNotification") as RadTextBox).Text;

 

 

;

 

 

 

 

 newRow["vchNewsText"] = s1;

 

 

 

 

 

newRow[

"dtStart"] = DateTime.Today;

 

 

newRow[

"dtInsertDate"] = DateTime.Today;

 

dsAlertTable.Rows.Add(newRow);

 

// rgIDCAlert.DataSource = dsAlertTable;

 

 

 

 

 

 

rgIDCAlert.MasterTableView.IsItemInserted =

false;

 

 

// rgIDCAlert.Rebind();

 

 

 

 

 

 

return;

 

}


And I use "Add New"  CommandItem to add empty row to grid;But I can't retrieve the input.

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