DateTime update field in C # GridView

I would like to split the DateTime for display and update in a GridView. How do I recombine them in the UpdateParameters SqlDataSource?

for example

<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>

      

Thank!

+2


source to share


1 answer


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 you have to enter or calculate the time portion of the date in minutes (which is what n in DATEADD means) in order to generate it correctly. How you do this is up to you.

+1


source







All Articles