Edit one field in a grid view

10 posts, 2 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 15 Aug 2011 Link to this post

    I'm looking for just a concept idea on this. I have a grid view and I would like one field to show data. Then, when you click on it, it changes to a text box that is editable and a user can edit that field and save it. Any thoughts on how to do this? I also thought about showing a tool tip on click with a text box and save button. Which do you think is better/easier?
  2. Answer
    Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 15 Aug 2011 Link to this post

    I'm doing this in an app
    <telerik:GridTemplateColumn UniqueName="Qty" HeaderText="Cases" DataField="Qty" DataType="System.Int32" Aggregate="Sum" >
        <ItemTemplate>
            <asp:Label ID="lblQty" Text='<%# Bind("Qty") %>' Width="40px" runat="server" />
        </ItemTemplate>
        <EditItemTemplate>
            <telerik:RadNumericTextBox ID="rntbQty" Value='<%# Eval("Qty") %>' OnTextChanged="rntbQty_TextChanged" AutoPostBack="True" Width="40px" runat="server">
                <NumberFormat DecimalDigits="0" />
            </telerik:RadNumericTextBox>
        </EditItemTemplate>
        <HeaderStyle Width="40px" />
    </telerik:GridTemplateColumn>

    ....
            </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
                <ClientEvents OnRowClick="RowClick" />
    protected void rntbQty_TextChanged(object sender, EventArgs e)
    {
        RadNumericTextBox rntbQty;
        GridDataItem gdItem;
        GridEditableItem geItem;
        DateTime ShipDate;
        int Qty,iBooth,iPage,iConsolid;
        double fStore,dVendor,dItemID,dNetCost;
        string[] strDel = new string[1];
        double[] dQty = new double[1];
        Hashtable CornedBeef;
        WsOrderSystem wsOrder;
        bool bUpdate = false;
     
        rntbQty = (RadNumericTextBox)sender;
        gdItem = rntbQty.NamingContainer as GridDataItem;
        geItem = rntbQty.NamingContainer as GridEditableItem;
        CornedBeef = new Hashtable();
        gdItem.ExtractValues(CornedBeef);
        ShipDate = Convert.ToDateTime(CornedBeef["ShipDate"]);
        Qty = Convert.ToInt32(rntbQty.Value);
        fStore = Convert.ToDouble(ExtractValue(geItem, "StoreNumber"));
        iBooth = Convert.ToInt32(ExtractValue(geItem, "BoothNumber"));
        iPage = Convert.ToInt32(ExtractValue(geItem, "PageNumber"));
        dVendor = Convert.ToDouble(ExtractValue(geItem, "VendorNumber"));
        dNetCost = Convert.ToDouble(ExtractValue(geItem, "NetCost"));       
        dItemID = Convert.ToDouble(ExtractValue(geItem, "ItemID"));
        iConsolid = Convert.ToInt32(txtConsolid.Value);
        strDel[0] = ShipDate.ToShortDateString();
        dQty[0] = Qty;
        wsOrder = new WsOrderSystem();
        bUpdate = wsOrder.AddToOrder(fStore,iBooth,iPage,dVendor,dNetCost,dItemID,strDel,dQty,true,iConsolid);   
    }

            </ClientSettings>
            </telerik:RadGrid>
    <telerik:RadCodeBlock ID="rcBlock" runat="server">
    <script type="text/javascript">
    <!--
    function RowDblClick(sender, eventArgs) {
        idx = eventArgs.get_itemIndexHierarchical();
        sender.get_masterTableView().editItem(idx);
        }
    function RowClick(sender, eventArgs) {
        idx = eventArgs.get_itemIndexHierarchical();
        sender.get_masterTableView().editItem(idx);
        }
    -->
    </script>
    </telerik:RadCodeBlock>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 15 Aug 2011 Link to this post

    I'm running into an issue with the text box. My visual basic is saying it can't find the text box. Here is my aspx

    <telerik:GridTemplateColumn DataField="goalhours" HeaderText="Goal" SortExpression="goalHours"
        UniqueName="goalHours" HeaderStyle-Width="80px">
        <ItemTemplate>
            <asp:Label ID="goalOutput" runat="server" Text='<%# Bind("goalHours") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <telerik:RadNumericTextBox ID="goalHoursInput" Runat="server" Value='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">
                <NumberFormat DecimalDigits="2" />
            </telerik:RadNumericTextBox>
        </EditItemTemplate>
    </telerik:GridTemplateColumn>

    And here is my code behind
    Protected Sub goalHoursInput_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
     
        Dim textBox As RadNumericTextBox = goalHoursInput
        Dim gridItem As GridDataItem
     
     
    End Sub 'end sub
    I'm getting an error saying 'goalHoursInput' is not declared. It may be inaccessible due to its protection level.

  5. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 15 Aug 2011 Link to this post

    the sender is the textbox
    Dim rntbQty as RADNumericTextBox
    rntbQty = DirectCast(sender,RadNumericTextBox)

    put that in your TextChanged event
  6. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 15 Aug 2011 Link to this post

    I see, thanks. I'm getting an issue when you click the text box, I see it does the post back but I get a cast issue. I should mention that I populate this grid with a custom data table that I built on the back end. However, I'm pretty sure I'm populating that field with a double. Here's the error.

    Exception Details: System.InvalidCastException: Specified cast is not valid.

    Source Error: 

    Line 78:                         </ItemTemplate>
    Line 79:                         <EditItemTemplate>
    Line 80:                             <telerik:RadNumericTextBox ID="goalHoursInput" Runat="server" Value='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">
    Line 81:                                 <NumberFormat DecimalDigits="2" />
    Line 82:                             </telerik:RadNumericTextBox>
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Aug 2011 Link to this post

    Hello,

    Try the following code snippet to achieve the scenario.

    VB:
    Protected Sub txt_TextChanged(sender As Object, e As EventArgs)
        Dim txt As RadNumericTextBox = TryCast(sender, RadNumericTextBox)
        Dim item As GridEditableItem = DirectCast(txt.NamingContainer, GridEditableItem)
    End Sub

    Thanks,
    Princy.
  8. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 16 Aug 2011 Link to this post

    I changed the radnumeric to just a rad textbox and it worked. However, that's not exactly what I was looking for. I want to just change that one column to a text box within the actual line. I don't need everything to be editable, just that one field. Any ideas?
  9. Answer
    Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 17 Aug 2011 Link to this post

    set every other column in yoyur RADGrid to ReadOnly="True"
  10. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 17 Aug 2011 Link to this post

    You are awesome, thanks.
  11. Paul
    Paul avatar
    2 posts
    Member since:
    Jan 2014

    Posted 22 Jan 2014 Link to this post

    Just Change Value to text Mean from
     Value='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">

    TO

     Text='<%# Eval("goalHours") %>' AutoPostBack="true" Width="40px">
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017