Set Default Value for column

3 posts, 1 answers
  1. Tim
    Tim avatar
    11 posts
    Member since:
    May 2009

    Posted 25 Nov 2009 Link to this post

    This should be simple but I've tried many different approaches and just can't get it.  All I want to do is set a default value of todays date in a raddatepicker control I have in a radgrid when the user clicks "Add New Record" in the header.  The markup is below.  It's the "txtTransactionDateNew" column I want to set the value in.  I'm using vb.

    <

     

    telerik:RadGrid ID="rgTransactions" runat="server" AllowPaging="True" DataSourceID="dsTransactions" GridLines="None" AutoGenerateEditColumn="True" Skin="Office2007" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True">

     

     

     

    <

     

    MasterTableView autogeneratecolumns="False" datakeynames="TransactionID"  datasourceid="dsTransactions" Caption="Transactions" EditMode="EditForms"  commanditemdisplay="Top" InsertItemPageIndexAction="ShowItemOnFirstPage">

     

     

    <CommandItemSettings AddNewRecordText="Add New Transaction" />

     

    <Columns>

     

    <

     

    telerik:GridBoundColumn DataField="TransactionID" ReadOnly="True" HeaderText="TransactionID" SortExpression="TransactionID" Visible="false" UniqueName="TransactionID" DataType="System.Int32"></telerik:GridBoundColumn>

     

     

    <

     

    telerik:GridBoundColumn DataField="DonorID" HeaderText="DonorID" Visible="false" SortExpression="DonorID" UniqueName="DonorID" DataType="System.Int32" ReadOnly="true"></telerik:GridBoundColumn>

     

     

    <telerik:GridTemplateColumn DataField="CheckNumber" HeaderText="Check Number" SortExpression="CheckNumber" UniqueName="CheckNumber">

     

    <EditItemTemplate>

     

    <telerik:RadTextBox ID="txtCheckNumber" Runat="server" Skin="Office2007"

     

    Text='<%# Bind("CheckNumber") %>' Width="125px">

     

    </telerik:RadTextBox>

     

    </EditItemTemplate>

     

    <ItemTemplate>

     

    <asp:Label ID="CheckNumberLabel" runat="server"

     

    Text='<%# Eval("CheckNumber") %>'></asp:Label>

     

    </ItemTemplate>

     

    </telerik:GridTemplateColumn>

     

    <telerik:GridTemplateColumn DataField="CreditAmount" HeaderText="Credit Amount"

     

    SortExpression="CreditAmount" UniqueName="CreditAmount">

     

    <EditItemTemplate>

     

    <telerik:RadNumericTextBox ID="txtCreditAmount" Runat="server"

     

    Culture="English (United States)" DbValue='<%# Bind("CreditAmount") %>'

     

    Skin="Office2007" Type="Currency" Width="125px">

     

    </telerik:RadNumericTextBox>

     

    </EditItemTemplate>

     

    <ItemTemplate>

     

    <asp:Label ID="CreditAmountLabel" runat="server"

     

    Text='<%# Eval("CreditAmount") %>'></asp:Label>

     

    </ItemTemplate>

     

    </telerik:GridTemplateColumn>

     

    <telerik:GridTemplateColumn DataField="DateEntered" HeaderText="Date Entered"

     

    SortExpression="DateEntered" UniqueName="DateEntered">

     

    <EditItemTemplate>

     

    <telerik:RadDatePicker ID="txtTransactionDateNew" Runat="server"

     

    Culture="English (United States)" DbSelectedDate='<%# Bind("DateEntered") %>'

     

    Skin="Office2007">

     

    <calendar skin="Office2007" usecolumnheadersasselectors="False"

     

    userowheadersasselectors="False" viewselectortext="x" ShowRowHeaders="False">

     

    </calendar>

     

    </telerik:RadDatePicker>

     

    </EditItemTemplate>

     

    <ItemTemplate>

     

    <asp:Label ID="DateEnteredLabel" runat="server"

     

    Text='<%# Eval("DateEntered") %>'></asp:Label>

     

    </ItemTemplate>

     

    </telerik:GridTemplateColumn>

     

    <telerik:GridCheckBoxColumn DataField="FifteenPercent"

     

    DataType="System.Boolean" HeaderText="Fifteen Pct"

     

    SortExpression="FifteenPercent" UniqueName="FifteenPercent">

     

    </telerik:GridCheckBoxColumn>

     

    <

     

    telerik:GridBoundColumn DataField="SortDate" HeaderText="SortDate"

     

     

    SortExpression="SortDate" UniqueName="SortDate" DataType="System.DateTime"

     

    ReadOnly="True" Visible="False"></telerik:GridBoundColumn>

     

    <telerik:GridButtonColumn CommandName="Delete"

     

    ConfirmText="Are you sure you want to delete this transaction?" Text="Delete"

     

    UniqueName="column">

     

    </telerik:GridButtonColumn>

     

    </Columns>

     

    </

     

    MasterTableView>

     

     

    <ClientSettings EnablePostBackOnRowClick="True">

     

    <Selecting AllowRowSelect="True" />

     

    </ClientSettings>

     

    </telerik:RadGrid>

     

     

     

     

  2. Answer
    Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 25 Nov 2009 Link to this post

    Hello,

    You can do that by attaching to ItemCreated event:

    Private Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
      If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then  
     If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then 
          If e.Item.OwnerTableView.IsItemInserted Then           
        Dim picker As RadDatePicker = CType(e.Item.FindControl("txtTransactionNewDate"), RadDatePicker)  
    picker.SelectedDate = DateTime.Now  
          Else 
              'item is about to be edited 
          End If 
       End If 
     
     
      End If  
    End Sub  
     
     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim
    Tim avatar
    11 posts
    Member since:
    May 2009

    Posted 26 Nov 2009 Link to this post

    It wasn't working in the ItemCreated event for some reason but I tried the ItemDataBound event and it worked.  I would have expected it to work in ItemCreated also so maybe it's the way I have something else configued.  Here it is converted to VB for anyone else who may benefit.  Thanks for putting me on the right track!

     

     

    Protected Sub rgTransactions_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgTransactions.ItemDataBound

     

     

    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then

     

     

     

        Dim picker As RadDatePicker = TryCast(e.Item.FindControl("txtTransactionDateNew"), RadDatePicker)

     

        picker.SelectedDate = DateTime.Now

     

    End If

     

     

     

     

     

    End Sub

    Tim

     

Back to Top