views:

489

answers:

1

Hi, I'd like to split apart a DateTime for both display and update within a GridView. How do I recombine them in the UpdateParameters of the SqlDataSource?

For instance

<asp:SqlDataSource ID="uxTravelTripMeetingDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MGO %>" 
            ProviderName="<%$ ConnectionStrings:MGO.ProviderName %>" 
            SelectCommand="select * from v_travel_meeting t where travel_trip_id = :travel_trip_id" 
            UpdateCommand="update travel_prospect set person = :person, meeting_date = :meeting_date where prospect_id = :prospect_id and travel_trip_id = :travel_trip_id "
            <SelectParameters>
                <asp:QueryStringParameter Name="travel_trip_id" QueryStringField="id" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="person" />
                <asp:Parameter Name="prospect_id" />
                <asp:Parameter Name="travel_trip_id"/>
                <asp:Parameter Name="meeting_date" Type="DateTime" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:GridView ID="uxTravelTripMeetingGridView" runat="server" 
            DataSourceID="uxTravelTripMeetingDataSource" AutoGenerateColumns="False" 
            DataKeyNames="travel_trip_id,prospect_id">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:TemplateField HeaderText="Prospect">
                <ItemTemplate>
                   <a href="something.aspx?prospectid=<%# Eval("prospect_id") %>&height=500&width=600" title="caption" class="thickbox" ><%# Eval("prospect_name")%>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="person" HeaderText="Person" />                    
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" 
                            Text='<%# Bind("meeting_date", "{0:d}") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" 
                            Text='<%# Bind("meeting_date", "{0:d}") %>' />
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" 
                            Text='<%# Bind("Meeting_time") %>'></asp:Label>&nbsp;
                        <asp:Label ID="Label4" runat="server" 
                            Text='<%# Bind("Meeting_am_pm") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                                <asp:ObjectDataSource ID="ds15Min" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="DDLFifteenMin" TypeName="App" />

                        <asp:DropDownList ID="DropDownList2" runat="server" 
                        DataSourceID="ds15Min" DataTextField="time" DataValueField="display" 
                            SelectedValue='<%# Bind("meeting_date","{0:t}") %>' >
                              <asp:ListItem Value=" "> </asp:ListItem>
                            </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
            </Columns>

        </asp:GridView>

Thanks!

A: 

Update command:

update travel_prospect set person = :person, meeting_date = DATEADD(n,@Date,@Time) 
where prospect_id = :prospect_id and travel_trip_id = :travel_trip_id

Update Parameters:

<asp:Parameter Name="Date" Type="DateTime" />
<asp:Parameter Name="Time" Type="String" />

Now this solution means that you must enter or calculate the time portion of the date in minutes (that is what n in DATEADD means) in order to create it correctly. How you do that is up to you.

Matthew Jones
That sort of works... I'm using Oracle, but I can translate DATEADD myself [to_date(To_Char(date) || ' ' || :time, 'DD-MON-YY HH:MI AM')], the only thing that is not clear to me is how to bind the parameters in the gridview to the made up parameter names.
Lloyd
the only thing that is not clear to me is how to bind the parameters in the gridview to the parameters which are split from the original field.
Lloyd