2

I asked this on the telerik forums, but sometimes responses can be slow there. I was wondering if anyone here know how to go about this.

I am in a situation where a user will have a variable number of items and beside each item I want a RadNumericTextBox. I was thinking of using the RadListView and setting the template to be the item name and a RadNumericTextBox associated with it. I want to ignore the edit, create, and the more advanced features of the RadListView. I just want a list of items with the input boxes that will auto post back when a user has changed the value.

The problem I am facing is when a user changes a number in the text box, how do I know which text box this is? I was looking to see if there was a attribute on RadNumericTextBox that could hold an arbitrary value such as my item key so I would know which number they changed. However, I don't see such an attribute.

Is there some way I can make a determination which text box they edited when I auto post back?

In case anyone asks, I do not want to force my user to click a button to make the row go into edit mode, change the number, then click a button to save the row.

Justin
  • 6,373
  • 9
  • 46
  • 72

2 Answers2

0

You could do this with a Repeater control.

Include a RadNumericTextBox in the repeater's item template, and then write a server-side event handler for it. The client ID of the text box can be accessed through the event handler's sender object, but if that isn't enough information you can rely on the repeater's data source to relate whatever data you need with each text box.

The simplest way might be to use the Label attribute of the text box. Here's an example:

ASPX:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server">    
    <ItemTemplate>
        <br />
        <telerik:RadNumericTextBox ID="radNTB" runat="server" AutoPostBack="true" OnTextChanged="radNTB_TextChanged" ClientIDMode="Predictable"></telerik:RadNumericTextBox>
    </ItemTemplate>
</asp:Repeater>

VB:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then

        Dim dt As New DataTable
        dt.Columns.Add("Column1", GetType(String))

        For i As Integer = 1 To 5
            Dim row = dt.NewRow
            row.Item("Column1") = "TextBox" & i.ToString
            dt.Rows.Add(row)
            dt.AcceptChanges()
        Next

        Repeater1.DataSource = dt
        Repeater1.DataBind()

    End If
End Sub

Private Sub Repeater1_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
    If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then

        Dim tb As RadNumericTextBox = e.Item.FindControl("radNTB")
        tb.Label = DataBinder.Eval(e.Item.DataItem, "Column1").ToString()

    End If
End Sub

Public Sub radNTB_TextChanged(sender As Object, e As EventArgs)
    Dim ntb As RadNumericTextBox = sender
    Response.Write(ntb.Label)
End Sub
kwinwithak
  • 96
  • 6
0

What you can do is by the item your binding the listview with the data source, make the id of the RadNumericTextBox equals to your item key that you want to pass. In the RadNumericTextBox TextChanged event cast the sender object to RadNumericTextBox type. in this case you will get the unique item key you are looking for. example :

<asp:FormView ID="frmViewPicture" runat="server">
  <EditItemTemplate>
    <telerik:RadNumericTextBox ID='Eval("ItemKey")' 
          OnTextChanged="radTxtNewPrice_TextChanged" AutoPostBack="true">
    </telerik:RadNumericTextBox>                                   
   </EditItemTemplate>
</asp:FormView>

Make sure the item key is unique and available in your data source, other wise you will get an exception.

protected void radTxtNewPrice_TextChanged(object sender, EventArgs e)
{
   Telerik.Web.UI.RadNumericTextBox txtRadNumericTextBox= (Telerik.Web.UI.RadNumericTextBox)sender;
   var itemKey = txtRadNumericTextBox.ID;
   // Do Your Logic Here 

}

Hope this is helpful.

user123456
  • 2,524
  • 7
  • 30
  • 57