?
Solved

Specify parameter value updating gridview

Posted on 2010-01-10
5
Medium Priority
?
327 Views
Last Modified: 2012-05-08
I have a gridview that is bound to a sqldatasource. When the user enters a complete date, I want to programmatically set the priority parameter value to "PEND"
I don't think this is rocket science but the "how" of it all escapes me.
I'm attaching both the aspx code and the code behind and would really appreciate some help.
<asp:GridView ID="tdGridView" runat="server" AutoGenerateColumns="False" BackColor="White"
        BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="rec_id"
        DataSourceID="NewTDSqlDataSource" GridLines="Horizontal">
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <Columns>
          <asp:CommandField ShowEditButton="True" />
          <asp:TemplateField HeaderText="rec_id" InsertVisible="False" SortExpression="rec_id">
            <EditItemTemplate>
              <asp:Label ID="Label1" runat="server" Text='<%# Eval("rec_id") %>'></asp:Label>
            </EditItemTemplate>
            <ItemTemplate>
              <asp:Label ID="Label1" runat="server" Text='<%# Bind("rec_id") %>'></asp:Label>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="priority" SortExpression="priority">
            <EditItemTemplate>
              <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("priority") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
              <asp:Label ID="Label2" runat="server" Text='<%# Bind("priority") %>'></asp:Label>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="tool_design_complete_date" SortExpression="tool_design_complete_date">
            <EditItemTemplate>
              <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("tool_design_complete_date") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
              <asp:Label ID="Label3" runat="server" Text='<%# Bind("tool_design_complete_date") %>'></asp:Label>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="design_notes" SortExpression="design_notes">
            <EditItemTemplate>
              <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("design_notes") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
              <asp:Label ID="Label4" runat="server" Text='<%# Bind("design_notes") %>'></asp:Label>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <AlternatingRowStyle BackColor="#F7F7F7" />
      </asp:GridView>
<asp:SqlDataSource ID="NewTDSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:App_DBConnectionString %>"
        SelectCommand="SELECT [rec_id], [priority], [tool_design_complete_date], [design_notes] FROM [Toolroom] WHERE (([complete_date] IS NULL) AND ([tool_design] = @tool_design) AND ([priority] <> @priority))" 
        UpdateCommand="UPDATE [Toolroom] SET [priority] = @priority, [tool_design_complete_date] = @tool_design_complete_date, [design_notes] = @design_notes WHERE [rec_id] = @rec_id">
        <SelectParameters>
          <asp:Parameter DefaultValue="YES" Name="tool_design" Type="String" />
          <asp:Parameter DefaultValue="PEND" Name="priority" Type="String" />
        </SelectParameters>
        <UpdateParameters>
          <asp:Parameter Name="priority" Type="String" />
          <asp:Parameter DbType="DateTime" Name="tool_design_complete_date" />
          <asp:Parameter Name="design_notes" Type="String" />
          <asp:Parameter Name="rec_id" Type="Decimal" />
        </UpdateParameters>
      </asp:SqlDataSource>
*CODE BEHIND*
Protected Sub tdGridView_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles tdGridView.RowUpdating
    If IsDate(e.NewValues("tool_complete_date")) Then
      Me.ToolDesignSqlDataSource.UpdateCommand = ""
      e.NewValues("priority") = "PEND"    
    End If
  End Sub

Open in new window

0
Comment
Question by:lakhi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 14

Expert Comment

by:robasta
ID: 26281675
TYPO:

 If IsDate(e.NewValues("tool_complete_date")) Then

should be

 If IsDate(e.NewValues("tool_design_complete_date")) Then
0
 

Author Comment

by:lakhi
ID: 26286288
The problem turned out to be "NewValues" is not accessible when templates are used in the gridview. It's necessary to use "FindControl"
I went back to my original and tried this but I'm still missing somethin because the complete date gets updated but the priority remains unchanged:
Protected Sub toolDesignGridview_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles tdcGridview.RowUpdating
    ' Dim gvr As GridViewRow = Me.toolDesignGridview.Rows(Me.toolDesignGridview.EditIndex)
    Dim tb1 As TextBox = CType(tdcGridview.Rows(e.RowIndex).FindControl("toolDesignCompDateTextBox"), TextBox)
    Dim priTB As TextBox = CType(tdcGridview.Rows(e.RowIndex).FindControl("priTextBox"), TextBox)

    If IsDate(tb1.Text) Then priTB.Text = "PEND"
  End Sub

Open in new window

0
 

Accepted Solution

by:
lakhi earned 0 total points
ID: 26288581
This is what I wound up doing and it finally worked:
Protected Sub toolDesignGridview_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles tdcGridview.RowUpdating
    Dim tb1 As TextBox = CType(tdcGridview.Rows(e.RowIndex).FindControl("toolDesignCompDateTextBox"), TextBox)
    Dim priTB As TextBox = CType(tdcGridview.Rows(e.RowIndex).FindControl("priTextBox"), TextBox)

    If IsDate(tb1.Text) Then
      Me.ToolDesignSqlDataSource.UpdateParameters("priority").DefaultValue = "PEND"
    Else
      Me.ToolDesignSqlDataSource.UpdateParameters("priority").DefaultValue = priTB.Text
    End If
  End Sub

And I adding the "RowUpdating" to the gridview
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question