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

Textarea in inline edit

4 Answers 348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 07 Feb 2012, 03:32 PM
I need to change the default small textbox to a textarea in edit mode ( inline) and it's not working, the textarea shows up when i use a template column but when it tries to update the textarea value it throws an error because it cannot find the value even though I set up Update params in the SQL datasource. Is there any sample projects that do this? I am wondering if it cannot find the value because I am using master pages.

Here is the code for the grid:

<telerik:RadGrid ID="rgNews" runat="server" CellSpacing="0"
                    DataSourceID="sdsNews" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" GridLines="None" AllowPaging="True"
                    AllowSorting="True" AutoGenerateColumns="False">
                    <ClientSettings>
                        <Selecting AllowRowSelect="True" />
                    </ClientSettings>
<MasterTableView DataKeyNames="newsID" CommandItemDisplay="Top" AllowAutomaticInserts="true" DataSourceID="sdsNews">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
 
    <Columns>
        <telerik:GridBoundColumn DataField="newsID" DataType="System.Int32"
            FilterControlAltText="Filter newsID column" HeaderText="newsID"
            ReadOnly="True" SortExpression="newsID" UniqueName="newsID"
            Visible="False">
        </telerik:GridBoundColumn>
        <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelText=""
            FilterControlAltText="Filter EditCommandColumn column"
            UpdateText="">
        </telerik:GridEditCommandColumn>
        <telerik:GridBoundColumn DataField="Title"
            FilterControlAltText="Filter Title column" HeaderText="Title"
            SortExpression="Title" UniqueName="Title">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Date"
            FilterControlAltText="Filter Date column" HeaderText="Date"
            SortExpression="Date" UniqueName="Date">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Author"
            FilterControlAltText="Filter Author column" HeaderText="Author"
            SortExpression="Author" UniqueName="Author">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Publication"
            FilterControlAltText="Filter Publication column" HeaderText="Publication"
            SortExpression="Publication" UniqueName="Publication">
        </telerik:GridBoundColumn>
       <%-- <telerik:GridBoundColumn DataField="Content"
            FilterControlAltText="Filter Content column" HeaderText="Content"  Visible="False"
            SortExpression="Content" UniqueName="Content">
        </telerik:GridBoundColumn>--%>
        <telerik:GridTemplateColumn UniqueName="Content" DataField="Content"  HeaderText="Content" Visible="false">
        <ItemTemplate>
        <asp:Label ID="lblContent" Text='<%# Bind("Content") %>' runat="server" />
        </ItemTemplate>
        <EditItemTemplate>
        <asp:TextBox ID="txtContent" TextMode="MultiLine" Text='<%# Eval("Content") %>' Height="150" Width="200" runat="server"></asp:TextBox>
        </EditItemTemplate>
        </telerik:GridTemplateColumn>
         <telerik:GridBoundColumn DataField="Link"
            FilterControlAltText="Filter Link column" HeaderText="Link"
            SortExpression="Link" Visible="false" UniqueName="Link">
        </telerik:GridBoundColumn>
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" ButtonType="ImageButton"
      UniqueName= "DeleteColumn" />
    </Columns>
 
<EditFormSettings CaptionFormatString="Edit news details for {0}" FormCaptionStyle-Font-Bold="true" FormCaptionStyle-ForeColor="#9d273f" CaptionDataField="Title">
<EditColumn FilterControlAltText="Filter EditCommandColumn column" ButtonType="ImageButton"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
 
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
                </telerik:RadGrid>

Here is the SQL Datasource code:

<asp:SqlDataSource ID="sdsNews" runat="server"
       ConnectionString="<%$ ConnectionStrings:CLSWEBConnectionString %>"     
       SelectCommand="SELECT [newsID], [Title], [Date], [Author], [Publication], [Content], [Link] FROM [tblNews]"
       UpdateCommand="UPDATE [tblNews] set [Title] = @Title, [Date] = @Date, [Author] = @Author, [Publication] = @Publication, [Content] = @Content, [Link] = @Link WHERE [newsID] = @newsID"
       DeleteCommand="DELETE FROM [tblNews] WHERE [newsID] = @newsID">
       <UpdateParameters>
       <asp:Parameter Name="Content" Type="String" />
       </UpdateParameters>
   </asp:SqlDataSource>



Here is the error it throws, I am guessing it cannot find the value of the Content template column:

Cannot insert the value NULL into column 'Content', table 'CLSWEB.dbo.tblNews'; column does not allow nulls. UPDATE fails.
The statement has been terminated.






Thanks,
Sam

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Feb 2012, 05:43 AM
Hello Sam,

I tried the same scenario which worked as expected in my end. Check the following demo which implements the same.
Grid / Automatic Operations

-Shinu.
0
Sam
Top achievements
Rank 1
answered on 08 Feb 2012, 04:26 PM
I got it to work, apparently you need to use a <telerik:RadTextBox for it to pick up the value........... Is there an easy way to set the width of the textboxes in edit mode? I saw a method suggested in the forums from a post 2 years ago and it looks like an unnecessary hassle to set something that should be exposed in the markup.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Feb 2012, 07:23 AM
Hello Sam,

You cannot change the width of RadTextBox in mark up. Try the following code to access RadTextBox in edit mode and set the width accordingly.
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
 {
  GridEditableItem item = (GridEditableItem)e.Item;  
  RadTextBox radtextbox1 = (RadTextBox)item.FindControl("RadTextBox1");                       
  radtextbox1.Width = Unit.Pixel(30);
 }
}

-Shinu.
0
Sam
Top achievements
Rank 1
answered on 09 Feb 2012, 03:47 PM
Thanks for the info. That seems like a HUGE miss on Telerik's end...... width should be set in markup.
Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Share this question
or