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

[?] Catch control's event in GridTemplateColumn

6 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tan
Top achievements
Rank 1
Tan asked on 15 Feb 2012, 12:57 AM
How can I catch control's event in GridTemplateColumn?
here is what I got:
------------------------------------------------------------------------------------------------------------------------------------------
<telerik:RadGrid Width="800px" ID="rgTest" runat="server" GridLines="None" AutoGenerateColumns="false" 
            AllowSorting="true" PageSize="3" onneeddatasource="rgTest_NeedDataSource" 
            ondeletecommand="rgTest_DeleteCommand" onitemcommand="rgTest_ItemCommand">
        <HeaderContextMenu EnableImageSprites="True"></HeaderContextMenu>
        <MasterTableView>
                <Columns>
                <telerik:GridBoundColumn DataField="ProductID" HeaderText="ID"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product Name"></telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Số lượng" InitializeTemplatesFirst="false" UniqueName="templatecolumns">
                    <ItemTemplate>
                    <div>
                        <telerik:RadNumericTextBox DataType="System.int16" value='<%#  int.Parse(Eval("Quantity").ToString()) %>' runat="server"></telerik:RadNumericTextBox>
                    </div>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridButtonColumn Text="delete" CommandName="Delete" Reorderable="true"></telerik:GridButtonColumn>
                </Columns>
                <RowIndicatorColumn><HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                <ExpandCollapseColumn><HeaderStyle Width="20px"></HeaderStyle>
                </ExpandCollapseColumn>
            </MasterTableView>
        </telerik:RadGrid>
---------------------------------------------------------------------------------------------------------------------------------------------------
This is my Grid:
[IMG]http://i1068.photobucket.com/albums/u450/bl4ir121/RadGrid1.png[/IMG]

I want when I edit quantity in a NumericTextBox of Quantity column, it will occur event and I can get value of this NumericTextbox to update list what I save in Session["ListProduct"].

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Feb 2012, 05:17 AM
Hello Tan,

I am not quite sure about your requirement. Try the following code to access the RadNumericTextBox.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
  GridDataItem item = (GridDataItem)e.Item;
  RadNumericTextBox rdnbx = (RadNumericTextBox)item.FindControl("RadNumericTextBox1");
 }
}

-Shinu.
0
Tan
Top achievements
Rank 1
answered on 15 Feb 2012, 02:03 PM
Hello Shinu,
I means when I change value in Quantity column (Quantity column is a GridTemplateColumn with ItemTemplate is NumericTextbox control ) , new value will be updated into Session["ListProduct"]. What does event occur when I change value? and How can I get new value to updated my ListProduct?
------------------------------------------
My datasource is ListProduct, type is List<Product> 
Class Product contain 3 attributes: ProductID, ProductName and Quantity.
ListProduct is saved in Session["ListProduct"]
I change value after ItemDataBound event occur.
------------------------------------------
Please help me. Thanks you very much!
P/s: this is my RadGrid in browser: http://i1068.photobucket.com/albums/u450/bl4ir121/RadGrid1.png
0
Casey
Top achievements
Rank 1
answered on 15 Feb 2012, 02:48 PM
Hi Tan,

You could specify the OnTextChanged event of the RadNumericTextBox and also set AutoPostBack to true for the RadNumericTextBox. 

TextChanged Event

protected void RadNumericTextBox1_TextChanged(object sender, EventArgs e)
{
    RadNumericTextBox ntb = (RadNumericTextBox)sender;
    Session["ListProduct"] = ntb.Value;
}

I hope this helps!
Casey
0
Tan
Top achievements
Rank 1
answered on 16 Feb 2012, 08:00 AM
Hi Casey,
thank you for your answer, I got value of NumericTextbox. but I have a question: a NumericTextbox cell also is a item of RadGrid, so, when it emit an event, that event also influence to RadGrid too, Is it right ?
Example:  RadGrid have ButtonColumn use to delete a row, it have CommandName property with value is "Delete"

<telerik:RadGrid ID="rgTest" AutoGenerateColumns="false" runat="server" ondeletecommand="rgTest_DeleteCommand">
...
<telerik:GridTemplateColumn  HeaderText="Quantity" InitializeTemplatesFirst="false" UniqueName="templatecolumns">
             <ItemTemplate>
  
<telerik:GridButtonColumn Text="Delete Record"  runat="server" CommandName="Delete"> </telerik:GridButtonColumn>
     </ItemTemplate>
</telerik:GridTemplateColumn >
...
</telerik:RadGrid >

GridButtonColumn cause Delete event and RadGrid link this event to function specified. So, please see code below:

<telerik:GridTemplateColumn   HeaderText="Quantity" InitializeTemplatesFirst="false" UniqueName="templatecolumns">
                    <ItemTemplate>
                    <div>
                        <telerik:RadNumericTextBox ID="txtQuantity"  runat="server" 
AutoPostBack="true" DataType="System.int16" value='<%# int.Parse(Eval("Quantity","{0:0}").ToString()) %>' OnTextChanged="TextChanged"></telerik:RadNumericTextBox>
                    </div>
                    </ItemTemplate>
</telerik:GridTemplateColumn>

my question is: Can RadGrid link text change event like ondeletecommand in first code paragraph.

( this is my first time I join in a foreign forum. I'am in Vietnamese so my english skill not good. If I have any mistake, I hope you can tell me. I'm very grateful to you. ^^



0
Casey
Top achievements
Rank 1
answered on 16 Feb 2012, 02:28 PM
Hi Tan,

I do not know of a way to have the TextChanged event of the RadNumericTextBox fire one of the RadGrid's events. Is there a specific reason you want it to be a RadGrid event instead of the TextChanged event?

Thanks,
Casey
0
Tan
Top achievements
Rank 1
answered on 16 Feb 2012, 10:36 PM
I just want to learn more. anyway, I thank you so much.  ^^
Tags
Grid
Asked by
Tan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tan
Top achievements
Rank 1
Casey
Top achievements
Rank 1
Share this question
or