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

[Solved] update database in radgridwiew on (textbox) itemtemplate textchanged

7 Answers 343 Views
Grid
This is a migrated thread and some comments may be shown as answers.
iclal
Top achievements
Rank 1
iclal asked on 01 Feb 2011, 02:46 PM
hi Telerik,I want to update my database table from gridview.But i use itemtemplate(textbox) for bind a table row.When ontextboxchanged I want to bind immediately other row,I try to tell with codes,Thanks..

<

 

 

telerik:RadGrid ID="SeviyeTamalanmaListesiRadGrid" runat="server"

 

 

 

AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"

 

 

 

EnableEmbeddedSkins="False" GridLines="None"

 

 

 

PagerStyle-FirstPageToolTip="Ilk Sayfa" PagerStyle-LastPageToolTip="Son Sayfa"

 

 

 

PagerStyle-NextPageToolTip="Sonraki Sayfa"

 

 

 

PagerStyle-PageSizeLabelText="Sayfa basina kayit sayisi:"

 

 

 

PagerStyle-PrevPageToolTip="Önceki Sayfa" Skin="WebBlueM"

 

 

 

OnPageIndexChanged="SeviyeTamalanmaListesiRadGrid_PageIndexChanged"

 

 

 

SortingSettings-SortToolTip="Siralamak için tiklayiniz." Width="469px"

 

 

 

onitemdatabound="SeviyeTamalanmaListesiRadGrid_ItemDataBound" >

 

 

 

<PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat="false" />

 

 

 

<HeaderContextMenu EnableAutoScroll="True">

 

 

 

</HeaderContextMenu>

 

 

 

<MasterTableView AllowFilteringByColumn="True"

 

 

 

DataKeyNames="SeviyeSablonID" ShowFooter="True" >

 

 

 

<NoRecordsTemplate>

 

Gösterilecek kayit yok.

 

 

</NoRecordsTemplate>

 

 

 

<Columns>

 

 

 

<telerik:GridBoundColumn AutoPostBackOnFilter="true"

 

 

 

CurrentFilterFunction="Contains" DataField="SeviyeSablonDetayID" HeaderText="SeviyeSablonDetayID"

 

 

 

ShowFilterIcon="false" SortExpression="SeviyeSablonDetayID" Visible="false" />

 

 

 

<telerik:GridBoundColumn AutoPostBackOnFilter="true"

 

 

 

CurrentFilterFunction="Contains" DataField="SeviyeSablonID" HeaderText="SeviyeSablonID"

 

 

 

ShowFilterIcon="false" SortExpression="SablonID" Visible="false"/>

 

 

 

<telerik:GridBoundColumn AutoPostBackOnFilter="true"

 

 

 

CurrentFilterFunction="Contains" DataField="SeviyeParametreAdi"

 

 

 

HeaderText="Seviye Adi" ShowFilterIcon="false"

 

 

 

SortExpression="SeviyeParametreAdi" HeaderStyle-Width="100px" FooterText="Toplam:"/>

 

 

 

 

<telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Pursantaj">

 

 

 

<HeaderStyle Width="25px" />

 

 

 

<ItemTemplate >

 

 

 

<asp:TextBox ID="SeviyeTanimlamaTextBox" runat="server" ReadOnly="true" Text='<%#Bind("PursantajDetay")%>' ToolTip="Seviye Pursantaj Degeri" Width="50px"></asp:TextBox>

 

 

 

</ItemTemplate>

 

 

 

<ItemStyle Width="25px" HorizontalAlign="center"/>

 

 

 

</telerik:GridTemplateColumn >

 

 

 

<telerik:GridTemplateColumn AllowFiltering="false" Aggregate="Sum" DataField="TamamlananPursantaj" DataType="System.Decimal"

 

 

 

SortExpression="TamamlananPursantaj" ShowFilterIcon="false" FooterStyle-HorizontalAlign="Right"

 

 

 

UniqueName="TamamlananPursantaj" FooterText=" " FooterStyle-Width="25px" HeaderText="Tamamlanan Pursantaj Yüzdesi">

 

 

 

<HeaderStyle Width="100px" />

 

 

 

<ItemTemplate >

 

 

 

<asp:TextBox ID="SeviyeTanimlamaYüzdesiTextBox" runat="server" ReadOnly="true" Text='<%#Bind("TamamlananPursantaj")%>' ToolTip="Seviye Pursantaj Degeri" Width="50px"></asp:TextBox>

 

 

 

</ItemTemplate>

 

 

 

<ItemStyle Width="25px" HorizontalAlign="center"/>

 

 

 

</telerik:GridTemplateColumn >

 

 

 

<telerik:GridTemplateColumn AllowFiltering="false"

 

 

 

HeaderText="Tamamlanan Pursantaj" >

 

 

 

<HeaderStyle Width="25px" />

 

 

 

<ItemTemplate>

 

 

 

--<%when this template text changed %>--
<
asp:TextBox ID="TamanalanmaYüzdesiTextBox" runat="server" ReadOnly="false" OnTextChanged="textBox_TextChangedRad" Text="" ToolTip="Seviye Pursantaj Degeri" Width="50px"></asp:TextBox>

 

 

 

</ItemTemplate>

 

 

 

<ItemStyle Width="25px" HorizontalAlign="center" />

 

 

 

</telerik:GridTemplateColumn>

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

 

<FilterMenu EnableEmbeddedSkins="False">

 

 

 

</FilterMenu>

 

 

 

<SortingSettings SortToolTip="Siralamak için tiklayiniz." />

 

 

 

 

</telerik:RadGrid>


this is grid pictures,i can update table when a buttonclick,if u want,but i cant solve that,too.
http://img705.imageshack.us/img705/6339/24028491.png

Thanks..

 

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Feb 2011, 06:55 AM
Hello Iclal,

In TextChanged event of TextBox, access the gridDataItem using NamingContainer property of Textbox. Then access the second TextBox using FindControl() method. Sample code is given below.

C#:
protected void textBox_TextChangedRad(object sender, EventArgs e)
   {
       TextBox txtbox = (TextBox)sender;
       GridDataItem item = (GridDataItem)txtbox.NamingContainer;
       TextBox txtbox2 = (TextBox)item.FindControl("SeviyeTanimlamaYüzdesiTextBox");
       txtbox2.Text = "new value";//updating TextBox value
       //query to update database
   }

Note: You need to set AutoPostBack property of TextBox (TamanalanmaYüzdesiTextBox)  as 'True' to fire OnTextChanged event.

Hope this helps,
Princy.
0
Anthony Mangini
Top achievements
Rank 1
answered on 16 Jul 2013, 06:32 PM
I am having the same issue.  I tried the code here but it does not seem to work.  I have a radgrid and inside the mastertableview I have an itemtemplate that has an asp panel then a table that contains a textbox and I want to fire the ontextchanged event and be able to access that text box.  here is my code. The user is actually dragging and dropping text from another field here and I want to remove what is there and replace it with what they are trying to drag into the textbox.
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1"
    AllowFilteringByColumn="False" runat="server" GridLines="None"
    AllowPaging="true" OnPreRender="RadGrid1_PreRender"
    AutoGenerateColumns="true">
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<MasterTableView ShowHeader="false" TableLayout="Fixed">
<ItemTemplate>
    <asp:Panel ID="ItemContainer" runat="server">
        <table  width="100%" class="table-NoBorder">
                <tr class="tblHeader" bgcolor="#617E97">
                    <td width="250">
                        <b>Name</b>
                    </td>
                </tr>
                <tr class="tblValue">
                    <td>
                        <b><asp:TextBox ID="txtName" runat="server" Text=<%#Eval("Name")%> Width="250" OnTextChanged="txtName_TextChanged" AutoPostBack="True"></asp:TextBox></b>
                    </td>
        </table>
    </asp:Panel>
</ItemTemplate>
</MasterTableView>
<GroupingSettings CaseSensitive="false"></GroupingSettings>
</telerik:RadGrid>

Protected Sub txtName_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim txtbox As TextBox = DirectCast(sender, TextBox)
        Dim item As GridDataItem = DirectCast(txtbox.NamingContainer, GridDataItem)
        Dim txtbox2 As TextBox = DirectCast(item.FindControl("txtName"), TextBox)
        txtbox2.Text = "new value"
    End Sub

0
Vasil
Telerik team
answered on 19 Jul 2013, 01:05 PM
Hi Anthony,

I am not sure what you are trying to achieve. In the code that you have provided you are using the TextChanged of one TextBox, then find the same text box, and in the end you are setting it's value to some predefined string.

If you want to use the value of 1 text box to fill the value of another. Then you should use 2 different TextBoxes.
What you mean that the user drags a text, and you want to use this text to change the original one? If the user has dropped the text, it is already changed, isn't it?

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Anthony Mangini
Top achievements
Rank 1
answered on 19 Jul 2013, 01:54 PM
Hi Vasil,

Thank you for the reply.  I actually figured this out and changed the way it is done to use a linkbutton instead of drag and drop which fires the item command and I can get the control and manipulate it there but one thing I am still having an issue with is trying to capture when the user hits enter on the textbox.  I tried to use a keydown event but it wont fire.  This is probably not the correct spot to post this but I figured since it was the same project and similarly related I would ask here.
0
Vasil
Telerik team
answered on 24 Jul 2013, 08:07 AM
Hello Anthony,

You should be able to handle the enter key with keydown DOM event, as the same way you can handle it for regular input element on the page.

However since the keydown is attached dynamically using attachEvent internally in the code of RadTextBox. If you use the AutoPostBack, a Postback will happen, and then the event will be canceled, to avoid triggering the default button on the page.

So if you like to handle the event using onkeydown attribute manually, then set AutoPostBack="false", for your inputs.

Another option will be to handle the RadInput Client Event called OnKeyPress.

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Anthony Mangini
Top achievements
Rank 1
answered on 02 Aug 2013, 05:15 PM
the asp:textbox called txtname in the code I pasted. Even if I change the autopostback="False" the onkeydown event is never triggered
0
Vasil
Telerik team
answered on 07 Aug 2013, 01:48 PM
Hi Anthony,

I don't see the relation between RadControls and the keydown of asp:TextBox. I thought you had a problem with RadTextBox.

If you insulate the problem in sample page, I will try to debug it, if the issue is really caused by any of our controls.

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
iclal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Anthony Mangini
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or