?
Solved

Default value for textbox in formview

Posted on 2008-06-19
2
Medium Priority
?
1,162 Views
Last Modified: 2008-06-23
Still new to the .net
I am tring to move fields from a gridview row (I can get the data) to a bound formview fields. Then enter additional fields and insert data into new table bound to the formview.

Code follows
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
              DataKeyNames="AssignmentID" DataSourceID="SqlDataSource2" Visible="False" 
              Width="652px"
              selectedindex="0"
              onselectedindexchanged="MGridView_SelectedIndexChanged" Height="157px">
              <Columns>
                  <asp:CommandField ShowSelectButton="True" />
                  <asp:BoundField DataField="AssignmentID" HeaderText="AssignmentID" 
                      InsertVisible="False" ReadOnly="True" SortExpression="AssignmentID" 
                      Visible="False" />
                  <asp:BoundField DataField="WorkPeriod" HeaderText="WorkPeriod" 
                      SortExpression="WorkPeriod" />
                  <asp:BoundField DataField="Employee" HeaderText="Employee" 
                      SortExpression="Employee" />
                  <asp:BoundField DataField="Shift" HeaderText="Shift" SortExpression="Shift" />
                  <asp:BoundField DataField="Level" HeaderText="Level" SortExpression="Level" />
                  <asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area" />
                  <asp:BoundField DataField="Boss" HeaderText="Boss" SortExpression="Boss" />
                  <asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
              </Columns>
          </asp:GridView>
            </td>
        </tr>
        <tr valign="top">
          <td class="storyLeft" style="width: 258px">
          <p> <a href="#" class="capsule"><strong></strong></a></p>          </td>
          <td>
            <p> <a href="#" class="capsule"></a> <a href="#"></a></p>          </td>
        </tr>
        <tr valign="top">
          <td class="storyLeft" style="width: 258px">
            <p> <a href="#" class="capsule"></a> <a href="#"></a> 
          <asp:Label ID="Message" runat="server"></asp:Label>
              </p>          </td>
          <td>
            <p> <a href="#" class="capsule"></a> <a href="#"></a>
              <asp:Label ID="Message2" runat="server"></asp:Label>
              </p>          </td>
        </tr>
      </table>
     <div class="feature">         
    
      
      <p style="width: 700px"><br />  
          <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
              ConnectionString="<%$ ConnectionStrings:SunshineConnectionString %>" 
              SelectCommand="SELECT * FROM [ShiftAssignments] WHERE ([Boss] = @Boss) ORDER BY [Employee]">
              <SelectParameters>
                  <asp:Parameter DefaultValue = "Dan Clark" Name="Boss" Type="String" />
              </SelectParameters>
          </asp:SqlDataSource>
        </p>
          
          <p> 
              <a href="#" class="capsule"></a>
              <br />
          </p>          
          
          <p> 
              <asp:FormView ID="FormView1" runat="server" DataKeyNames="TimeSheetID" 
                  DataSourceID="SqlDataSource3" DefaultMode="Insert" Width="351px">
                  <EditItemTemplate>
                      TimeSheetID:
                      <asp:Label ID="TimeSheetIDLabel1" runat="server" 
                          Text='<%# Eval("TimeSheetID") %>' />
                      <br />
                      workperiod:
                      <asp:TextBox ID="workperiodTextBox" runat="server" 
                          Text='<%# Bind("workperiod") %>' />
                      <br />
                      tsdate:
                      <asp:TextBox ID="tsdateTextBox" runat="server" Text='<%# Bind("tsdate") %>' />
                      <br />
                      job_description:
                      <asp:TextBox ID="job_descriptionTextBox" runat="server" 
                          Text='<%# Bind("job_description") %>' />
                      <br />
                      Level:
                      <asp:TextBox ID="LevelTextBox" runat="server" Text='<%# Bind("Level") %>' />
                      <br />
                      workarea:
                      <asp:TextBox ID="workareaTextBox" runat="server" 
                          Text='<%# Bind("workarea") %>' />
                      <br />
                      workplace:
                      <asp:TextBox ID="workplaceTextBox" runat="server" 
                          Text='<%# Bind("workplace") %>' />
                      <br />
                      grade:
                      <asp:TextBox ID="gradeTextBox" runat="server" Text='<%# Bind("grade") %>' />
                      <br />
                      days:
                      <asp:TextBox ID="daysTextBox" runat="server" Text='<%# Bind("days") %>' />
                      <br />
                      contract:
                      <asp:TextBox ID="contractTextBox" runat="server" 
                          Text='<%# Bind("contract") %>' />
                      <br />
                      shift:
                      <asp:TextBox ID="shiftTextBox" runat="server" Text='<%# Bind("shift") %>' />
                      <br />
                      reg:
                      <asp:TextBox ID="regTextBox" runat="server" Text='<%# Bind("reg") %>' />
                      <br />
                      ot1:
                      <asp:TextBox ID="ot1TextBox" runat="server" Text='<%# Bind("ot1") %>' />
                      <br />
                      ot2:
                      <asp:TextBox ID="ot2TextBox" runat="server" Text='<%# Bind("ot2") %>' />
                      <br />
                      holes:
                      <asp:TextBox ID="holesTextBox" runat="server" Text='<%# Bind("holes") %>' />
                      <br />
                      hole_length:
                      <asp:TextBox ID="hole_lengthTextBox" runat="server" 
                          Text='<%# Bind("hole_length") %>' />
                      <br />
                      powder:
                      <asp:TextBox ID="powderTextBox" runat="server" Text='<%# Bind("powder") %>' />
                      <br />
                      bolts_4:
                      <asp:TextBox ID="bolts_4TextBox" runat="server" Text='<%# Bind("bolts_4") %>' />
                      <br />
                      bolts_6:
                      <asp:TextBox ID="bolts_6TextBox" runat="server" Text='<%# Bind("bolts_6") %>' />
                      <br />
                      safety:
                      <asp:TextBox ID="safetyTextBox" runat="server" Text='<%# Bind("safety") %>' />
                      <br />
                      equipment:
                      <asp:TextBox ID="equipmentTextBox" runat="server" 
                          Text='<%# Bind("equipment") %>' />
                      <br />
                      employee:
                      <asp:TextBox ID="employeeTextBox" runat="server" 
                          Text='<%# Bind("employee") %>' />
                      <br />
                      employee_number:
                      <asp:TextBox ID="employee_numberTextBox" runat="server" 
                          Text='<%# Bind("employee_number") %>' />
                      <br />
                      <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                          CommandName="Update" Text="Update" />
                      &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                          CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                  </EditItemTemplate>
                  <InsertItemTemplate>
                      Work Period:
                      <asp:TextBox ID="workperiodTextBox" runat="server" 
                          Text='<%# Bind("workperiod") %>' />
                      <br />
                      Date:
                      <asp:TextBox ID="tsdateTextBox" runat="server" Text='<%# Bind("tsdate") %>' />
                      <br />
                      Job Description:
                      <asp:TextBox ID="job_descriptionTextBox" runat="server" 
                          Text='<%# Bind("job_description") %>' />
                      <br />
                      Level:
                      <asp:TextBox ID="LevelTextBox" runat="server" Text='<%# Bind("Level") %>' />
                      <br />
                      Work Area:
                      <asp:TextBox ID="workareaTextBox" runat="server" 
                          Text='<%# Bind("workarea") %>' />
                      <br />
                      Work Place:
                      <asp:TextBox ID="workplaceTextBox" runat="server" 
                          Text='<%# Bind("workplace") %>' />
                      <br />
                      Grade:
                      <asp:TextBox ID="gradeTextBox" runat="server" Text='<%# Bind("grade") %>' />
                      <br />
                      Day's Pay:
                      <asp:CheckBox ID="daysTextBox" runat="server" Text='<%# Bind("days") %>' />
                      Contract:
                      <asp:CheckBox ID="contractTextBox" runat="server" 
                          Text='<%# Bind("contract") %>' />
                      <br />
                      Shift:
                      <asp:TextBox ID="shiftTextBox" runat="server" Text='<%# Bind("shift") %>' />
                      <br />
                      Regular:
                      <asp:TextBox ID="regTextBox" runat="server" Text='<%# Bind("reg") %>' />
                      <br />
                      Over Time 1:
                      <asp:TextBox ID="ot1TextBox" runat="server" Text='<%# Bind("ot1") %>' />
                      <br />
                      Over Time 2:
                      <asp:TextBox ID="ot2TextBox" runat="server" Text='<%# Bind("ot2") %>' />
                      <br />
                      Holes:
                      <asp:TextBox ID="holesTextBox" runat="server" Text='<%# Bind("holes") %>' 
                          Width="35px" />
                      Hole Length:
                      <asp:TextBox ID="hole_lengthTextBox" runat="server" 
                          Text='<%# Bind("hole_length") %>' Width="40px" />
                      <br />
                      Powder:
                      <asp:TextBox ID="powderTextBox" runat="server" Text='<%# Bind("powder") %>' />
                      <br />
                      Bolts 4&quot;:
                      <asp:TextBox ID="bolts_4TextBox" runat="server" Text='<%# Bind("bolts_4") %>' 
                          Width="45px" />
                      Bolts 6&quot;:
                      <asp:TextBox ID="bolts_6TextBox" runat="server" Text='<%# Bind("bolts_6") %>' 
                          Width="40px" />
                      <br />
                      Safety:
                      <asp:CheckBox ID="safetyTextBox" runat="server" Text='<%# Bind("safety") %>' />
                      Equipment:
                      <asp:CheckBox ID="equipmentTextBox" runat="server" 
                          Text='<%# Bind("equipment") %>' />
                      <br />
                      
                      <asp:TextBox ID="employeeTextBox" runat="server" Text='<%# Bind("employee") %>' 
                          Visible="False" />
                      <br />
                      
                      <asp:TextBox ID="employee_numberTextBox" runat="server" 
                          Text='<%# Bind("employee_number") %>' Visible="False" />
                      <br />
                      <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                          CommandName="Insert" Text="Insert" />
                      &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                          CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                  </InsertItemTemplate>
                  <ItemTemplate>
                      TimeSheetID:
                      <asp:Label ID="TimeSheetIDLabel" runat="server" 
                          Text='<%# Eval("TimeSheetID") %>' />
                      <br />
                      workperiod:
                      <asp:Label ID="workperiodLabel" runat="server" 
                          Text='<%# Bind("workperiod") %>' />
                      <br />
                      tsdate:
                      <asp:Label ID="tsdateLabel" runat="server" Text='<%# Bind("tsdate") %>' />
                      <br />
                      job_description:
                      <asp:Label ID="job_descriptionLabel" runat="server" 
                          Text='<%# Bind("job_description") %>' />
                      <br />
                      Level:
                      <asp:Label ID="LevelLabel" runat="server" Text='<%# Bind("Level") %>' />
                      <br />
                      workarea:
                      <asp:Label ID="workareaLabel" runat="server" Text='<%# Bind("workarea") %>' />
                      <br />
                      workplace:
                      <asp:Label ID="workplaceLabel" runat="server" Text='<%# Bind("workplace") %>' />
                      <br />
                      grade:
                      <asp:Label ID="gradeLabel" runat="server" Text='<%# Bind("grade") %>' />
                      <br />
                      days:
                      <asp:Label ID="daysLabel" runat="server" Text='<%# Bind("days") %>' />
                      <br />
                      contract:
                      <asp:Label ID="contractLabel" runat="server" Text='<%# Bind("contract") %>' />
                      <br />
                      shift:
                      <asp:Label ID="shiftLabel" runat="server" Text='<%# Bind("shift") %>' />
                      <br />
                      reg:
                      <asp:Label ID="regLabel" runat="server" Text='<%# Bind("reg") %>' />
                      <br />
                      ot1:
                      <asp:Label ID="ot1Label" runat="server" Text='<%# Bind("ot1") %>' />
                      <br />
                      ot2:
                      <asp:Label ID="ot2Label" runat="server" Text='<%# Bind("ot2") %>' />
                      <br />
                      holes:
                      <asp:Label ID="holesLabel" runat="server" Text='<%# Bind("holes") %>' />
                      <br />
                      hole_length:
                      <asp:Label ID="hole_lengthLabel" runat="server" 
                          Text='<%# Bind("hole_length") %>' />
                      <br />
                      powder:
                      <asp:Label ID="powderLabel" runat="server" Text='<%# Bind("powder") %>' />
                      <br />
                      bolts_4:
                      <asp:Label ID="bolts_4Label" runat="server" Text='<%# Bind("bolts_4") %>' />
                      <br />
                      bolts_6:
                      <asp:Label ID="bolts_6Label" runat="server" Text='<%# Bind("bolts_6") %>' />
                      <br />
                      safety:
                      <asp:Label ID="safetyLabel" runat="server" Text='<%# Bind("safety") %>' />
                      <br />
                      equipment:
                      <asp:Label ID="equipmentLabel" runat="server" Text='<%# Bind("equipment") %>' />
                      <br />
                      employee:
                      <asp:Label ID="employeeLabel" runat="server" Text='<%# Bind("employee") %>' />
                      <br />
                      employee_number:
                      <asp:Label ID="employee_numberLabel" runat="server" 
                          Text='<%# Bind("employee_number") %>' />
                      <br />
                      <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                          CommandName="Edit" Text="Edit" />
                      &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                          CommandName="Delete" Text="Delete" />
                      &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                          CommandName="New" Text="New" />
                  </ItemTemplate>
                  <InsertRowStyle HorizontalAlign="Right" />
              </asp:FormView>
              <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                  ConnectionString="<%$ ConnectionStrings:SunshineConnectionString %>" 
                  DeleteCommand="DELETE FROM [TS2008] WHERE [TimeSheetID] = @TimeSheetID" 
                  InsertCommand="INSERT INTO [TS2008] ([workperiod], [tsdate], [employee], [employee_number], [job_description], [workplace], [grade], [days], [contract], [shift], [reg], [ot1], [ot2], [holes], [hole_length], [powder], [bolts_4], [bolts_6], [safety], [equipment]) VALUES (@workperiod, @tsdate, @employee, @employee_number, @job_description, @workplace, @grade, @days, @contract, @shift, @reg, @ot1, @ot2, @holes, @hole_length, @powder, @bolts_4, @bolts_6, @safety, @equipment)" 
                  SelectCommand="SELECT * FROM [TS2008]" 
                  UpdateCommand="UPDATE [TS2008] SET [workperiod] = @workperiod, [tsdate] = @tsdate, [employee] = @employee, [employee_number] = @employee_number, [job_description] = @job_description, [workplace] = @workplace, [grade] = @grade, [days] = @days, [contract] = @contract, [shift] = @shift, [reg] = @reg, [ot1] = @ot1, [ot2] = @ot2, [holes] = @holes, [hole_length] = @hole_length, [powder] = @powder, [bolts_4] = @bolts_4, [bolts_6] = @bolts_6, [safety] = @safety, [equipment] = @equipment WHERE [TimeSheetID] = @TimeSheetID">
                  <DeleteParameters>
                      <asp:Parameter Name="TimeSheetID" Type="Int32" />
                  </DeleteParameters>
                  <UpdateParameters>
                      <asp:Parameter Name="workperiod" Type="String" />
                      <asp:Parameter Name="tsdate" Type="String" />
                      <asp:Parameter Name="employee" Type="String" />
                      <asp:Parameter Name="employee_number" Type="String" />
                      <asp:Parameter Name="job_description" Type="String" />
                      <asp:Parameter Name="workplace" Type="String" />
                      <asp:Parameter Name="grade" Type="String" />
                      <asp:Parameter Name="days" Type="Int32" />
                      <asp:Parameter Name="contract" Type="Int32" />
                      <asp:Parameter Name="shift" Type="String" />
                      <asp:Parameter Name="reg" Type="String" />
                      <asp:Parameter Name="ot1" Type="String" />
                      <asp:Parameter Name="ot2" Type="String" />
                      <asp:Parameter Name="holes" Type="String" />
                      <asp:Parameter Name="hole_length" Type="String" />
                      <asp:Parameter Name="powder" Type="String" />
                      <asp:Parameter Name="bolts_4" Type="String" />
                      <asp:Parameter Name="bolts_6" Type="String" />
                      <asp:Parameter Name="safety" Type="Int32" />
                      <asp:Parameter Name="equipment" Type="Int32" />
                      <asp:Parameter Name="TimeSheetID" Type="Int32" />
                  </UpdateParameters>
                  <InsertParameters>
                      <asp:Parameter Name="workperiod" Type="String" />
                      <asp:Parameter Name="tsdate" Type="String" />
                      <asp:Parameter Name="employee" Type="String" />
                      <asp:Parameter Name="employee_number" Type="String" />
                      <asp:Parameter Name="job_description" Type="String" />
                      <asp:Parameter Name="workplace" Type="String" />
                      <asp:Parameter Name="grade" Type="String" />
                      <asp:Parameter Name="days" Type="Int32" />
                      <asp:Parameter Name="contract" Type="Int32" />
                      <asp:Parameter Name="shift" Type="String" />
                      <asp:Parameter Name="reg" Type="String" />
                      <asp:Parameter Name="ot1" Type="String" />
                      <asp:Parameter Name="ot2" Type="String" />
                      <asp:Parameter Name="holes" Type="String" />
                      <asp:Parameter Name="hole_length" Type="String" />
                      <asp:Parameter Name="powder" Type="String" />
                      <asp:Parameter Name="bolts_4" Type="String" />
                      <asp:Parameter Name="bolts_6" Type="String" />
                      <asp:Parameter Name="safety" Type="Int32" />
                      <asp:Parameter Name="equipment" Type="Int32" />
                  </InsertParameters>
              </asp:SqlDataSource>
Code Behind:
Sub MGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
 
        ' Get the currently selected row using the SelectedRow property.
        Dim mrow As GridViewRow = GridView2.SelectedRow
 
        ' Display the company name from the selected row.
        ' In this example, the third column (index 2) contains
        ' the company name.
        Message2.Text = "You selected " & mrow.Cells(3).Text & "."
        FormView1.FindControl("workperiod") = mrow.Cells(4).Text ,    <- Does not work
 
        'SqlDataSource3.SelectParameters("Employee").DefaultValue = row.Cells(1).Text
 
    End Sub

Open in new window

0
Comment
Question by:rbunkofske
[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 Comments
 

Author Comment

by:rbunkofske
ID: 21831478
Thanks for the help
0
 
LVL 10

Accepted Solution

by:
Oliver Amaya earned 1500 total points
ID: 21832689
Hi, you should pass the ID of the control in the FindControl method:
FormView1.FindControl("workperiodTextBox")

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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