-cr-
asked on
Changing hyperlink.
I have the hyperlink below that redirects the client to a page where they can isert a new record. I want this to load within the same page.
<asp:HyperLink ID="HyperLink1" ImageUrl="~/images/add.gif " Text="New" NavigateUrl="DetailsViewIn sert.aspx" runat="server" /><small>new</small>
*
First EquipmentType is selected, once a type is selected a search is done in inventory for this equipmenttype. This is displayed in a gridview in which the item can be selected or deleted. If selected it allows the option to edit or add a new record. I would like the functionality of the add to be used instead of having to use the hyperlink to a form as stated above. This seems to be redundant to me when the code already exists to do this. I hope I am not confusing the person reading this but I am not familar with the terminology for what I need to accomplish. Thanks.
Below is the code for the app :
<%@ Page Language="VB" %>
<script runat="server">
  Protected Sub DetailsView1_ItemInserted( ByVal sender As Object, ByVal e As System.Web.UI.WebControls. DetailsVie wInsertedE ventArgs)
 Â
    If (Not e.Exception Is Nothing) Then
      ErrorMessageLabel.Text = "An error occured while entering this record.  Please verify you have entered data in the correct format."
      e.ExceptionHandled = True
    End If
    GridView1.DataBind()
  End Sub
  Protected Sub DetailsView1_ItemUpdated(B yVal sender As Object, ByVal e As System.Web.UI.WebControls. DetailsVie wUpdatedEv entArgs)
 Â
    GridView1.DataBind()
  End Sub
  Protected Sub DropDownList1_SelectedInde xChanged(B yVal sender As Object, ByVal e As EventArgs)
 Â
  Â
    DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
   Â
  End Sub
  Protected Sub GridView1_SelectedIndexCha nged(ByVal sender As Object, ByVal e As EventArgs)
 Â
    DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
  End Sub
  Protected Sub GridView1_PageIndexChanged (ByVal sender As Object, ByVal e As EventArgs)
 Â
    DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
  End Sub
  Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs)
    DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
  End Sub
 Â
  Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)
 Â
    If (Not e.Exception Is Nothing) Then
   Â
      ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint on the table.  You may only delete rows which have no related records."
      e.ExceptionHandled = True
    End If
  End Sub
  Protected Sub DetailsView1_DataBound(ByV al sender As Object, ByVal e As EventArgs)
 Â
    If (DetailsView1.CurrentMode = DetailsViewMode.Insert) Then
   Â
      Dim stateTextBox As TextBox = CType(DetailsView1.Rows(6) .Cells(1). Controls(0 ), TextBox)
      stateTextBox.Text = DropDownList1.SelectedValu e
      stateTextBox.Enabled = False
    End If
  End Sub
  Protected Sub Dropdownlist1_DataBound(By Val sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.DataBound
    DropDownList1.Items.Insert (0, New ListItem("SELECT TYPE", "0"))
  End Sub
</script>
<html>
<head id="Head1" runat="server">
 <title>E-Risk Services Inventory</title>
<link rel="Stylesheet" href="style.css" />
</head>
<body>
 <form id="form1" runat="server">
  <b>Equipment Type:</b>
  <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSourc e2" AutoPostBack="true"
   DataTextField="equipmentty pe" runat="server" OnSelectedIndexChanged="Dr opDownList 1_Selected IndexChang ed" />
  <asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT [equipmenttype] FROM [equipmenttype]"
   ConnectionString="<%$ ConnectionStrings:BamAdmin Connection String %>" />
  Â
    <br />
  <br />
    <table cellpadding="0" cellspacing="0">
   <tr>
    <td valign="top" style="width: 555px; height: 309px;" colspan="">
   Â
     <asp:GridView ID="GridView1" AllowPaging="True" runat="server"
      DataSourceID="SqlDataSourc e1" DataKeyNames="id"
      AutoGenerateColumns="False " Width="500px" SelectedIndex="0" OnSelectedIndexChanged="Gr idView1_Se lectedInde xChanged" OnPageIndexChanged="GridVi ew1_PageIn dexChanged " OnRowDeleted="GridView1_Ro wDeleted" OnSorted="GridView1_Sorted " CellPadding="0" GridLines="None">
      <Columns>
       <asp:CommandField ShowSelectButton="True" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/images/d elete.gif" EditImageUrl="~/images/doc umentedit. gif" NewImageUrl="~/images/add. gif" CancelImageUrl="~/images/d elete.gif" SelectImageUrl="~/images/a pprove.gif " UpdateImageUrl="~/images/m oveup.gif" HeaderText="ACTION" >
         <HeaderStyle Wrap="False" CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" />
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
       </asp:CommandField>
       <asp:BoundField DataField="equipmenttype" HeaderText="TYPE" SortExpression="equipmentt ype" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="make" HeaderText="MAKE" SortExpression="make" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="model" HeaderText="MODEL" SortExpression="model" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="owner" HeaderText="OWNER" SortExpression="owner" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
      Â
       </asp:BoundField>
      </Columns>
       <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
       <AlternatingRowStyle CssClass="Tdatagray" />
         <EditRowStyle BackColor="#999999" />
         <RowStyle CssClass="tdatasilva" />
       <HeaderStyle Font-Size="X-Small" Font-Names="Tahoma" />
     </asp:GridView>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BamAdmin Connection String %>"
      SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([equipmenttype] = @equipmenttype)"
      DeleteCommand="DELETE FROM [hardwareinventory] WHERE [id] = @id">
      <SelectParameters>
       <asp:ControlParameter ControlID="DropDownList1" Name="equipmenttype" PropertyName="SelectedValu e"
        Type="String" />
      </SelectParameters>
     </asp:SqlDataSource>
     <asp:HyperLink ID="HyperLink1" ImageUrl="~/images/add.gif " Text="New" NavigateUrl="DetailsViewIn sert.aspx" runat="server" /><small>new</small>
     <asp:HyperLink ID="HyperLink2" ImageUrl="~/images/delete. gif" Text="Cnacel" NavigateUrl="Details.aspx" runat="server" /><small>cancel</small>
    </td>
    <td valign="top" style="width: 225px; height: 309px;">
     <asp:DetailsView AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSourc e3"
      HeaderText="<b>EQUIPMENT DETAILS</b>" CssClass="headertitle" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView 1_ItemUpda ted" OnItemInserted="DetailsVie w1_ItemIns erted" OnDataBound="DetailsView1_ DataBound" >
      <Fields>
       <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" InsertVisible="False" >
         <ItemStyle CssClass="box_title" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
         <HeaderStyle CssClass="tdatagray" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="make" HeaderText="make" SortExpression="make" >
         <ItemStyle CssClass="box_title" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
         <HeaderStyle CssClass="tdatagray" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="model" HeaderText="model" SortExpression="model" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="serial" HeaderText="serial" SortExpression="serial" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="owner" HeaderText="owner" SortExpression="owner" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmentt ype" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:CommandField ButtonType="Image" EditImageUrl="~/images/doc umentedit. gif" CancelImageUrl="~/images/d elete.gif"  InsertImageUrl="~/images/d isk.gif" NewImageUrl="~/images/add. gif" UpdateImageUrl="~/images/m oveup.gif" HeaderText="Action"
              ShowEditButton="True" ShowInsertButton="True">
         <HeaderStyle CssClass="tdata" />
         <ItemStyle CssClass="tdata" />
       </asp:CommandField>
      </Fields>
       <HeaderStyle Font-Size="XX-Small" />
     </asp:DetailsView>
     <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:BamAdmin Connection String %>"
      SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([id] = @id)"
      UpdateCommand="UPDATE [hardwareinventory] SET [equipmenttype] = @equipmenttype, [make] = @make, [model] = @model, [serial] = @serial, [owner] = @owner, [name] = @name WHERE [id] = @id"
      InsertCommand="INSERT INTO [hardwareinventory] ([equipmenttype], [make], [model], [serial], [owner], [name]) VALUES (@equipmenttype, @make, @model, @serial, @owner, @name)">
      <SelectParameters>
       <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValu e"
        Type="String" />
      </SelectParameters>
      <UpdateParameters>
       <asp:Parameter Name="equipmenttype" Type="String" />
       <asp:Parameter Name="make" Type="String" />
       <asp:Parameter Name="model" Type="String" />
       <asp:Parameter Name="serial" Type="String" />
       <asp:Parameter Name="owner" Type="String" />
       <asp:Parameter Name="name" Type="String" />
       <asp:Parameter Name="id" Type="String" />
      </UpdateParameters>
      <InsertParameters>
       <asp:Parameter Name="make" Type="String" />
       <asp:Parameter Name="model" Type="String" />
       <asp:Parameter Name="serial" Type="String" />
       <asp:Parameter Name="owner" Type="String" />
       <asp:Parameter Name="name" Type="String" />
       <asp:Parameter Name="equipmenttype" Type="String" />
      </InsertParameters>
     </asp:SqlDataSource>
    </td>
   </tr>
  </table>
  <br />
  <asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" />
 </form>
</body>
</html>
<asp:HyperLink ID="HyperLink1" ImageUrl="~/images/add.gif
*
First EquipmentType is selected, once a type is selected a search is done in inventory for this equipmenttype. This is displayed in a gridview in which the item can be selected or deleted. If selected it allows the option to edit or add a new record. I would like the functionality of the add to be used instead of having to use the hyperlink to a form as stated above. This seems to be redundant to me when the code already exists to do this. I hope I am not confusing the person reading this but I am not familar with the terminology for what I need to accomplish. Thanks.
Below is the code for the app :
<%@ Page Language="VB" %>
<script runat="server">
  Protected Sub DetailsView1_ItemInserted(
 Â
    If (Not e.Exception Is Nothing) Then
      ErrorMessageLabel.Text = "An error occured while entering this record.  Please verify you have entered data in the correct format."
      e.ExceptionHandled = True
    End If
    GridView1.DataBind()
  End Sub
  Protected Sub DetailsView1_ItemUpdated(B
 Â
    GridView1.DataBind()
  End Sub
  Protected Sub DropDownList1_SelectedInde
 Â
  Â
    DetailsView1.ChangeMode(De
   Â
  End Sub
  Protected Sub GridView1_SelectedIndexCha
 Â
    DetailsView1.ChangeMode(De
  End Sub
  Protected Sub GridView1_PageIndexChanged
 Â
    DetailsView1.ChangeMode(De
  End Sub
  Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs)
    DetailsView1.ChangeMode(De
  End Sub
 Â
  Protected Sub GridView1_RowDeleted(ByVal
 Â
    If (Not e.Exception Is Nothing) Then
   Â
      ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint on the table.  You may only delete rows which have no related records."
      e.ExceptionHandled = True
    End If
  End Sub
  Protected Sub DetailsView1_DataBound(ByV
 Â
    If (DetailsView1.CurrentMode = DetailsViewMode.Insert) Then
   Â
      Dim stateTextBox As TextBox = CType(DetailsView1.Rows(6)
      stateTextBox.Text = DropDownList1.SelectedValu
      stateTextBox.Enabled = False
    End If
  End Sub
  Protected Sub Dropdownlist1_DataBound(By
    DropDownList1.Items.Insert
  End Sub
</script>
<html>
<head id="Head1" runat="server">
 <title>E-Risk Services Inventory</title>
<link rel="Stylesheet" href="style.css" />
</head>
<body>
 <form id="form1" runat="server">
  <b>Equipment Type:</b>
  <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSourc
   DataTextField="equipmentty
  <asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT [equipmenttype] FROM [equipmenttype]"
   ConnectionString="<%$ ConnectionStrings:BamAdmin
  Â
    <br />
  <br />
    <table cellpadding="0" cellspacing="0">
   <tr>
    <td valign="top" style="width: 555px; height: 309px;" colspan="">
   Â
     <asp:GridView ID="GridView1" AllowPaging="True" runat="server"
      DataSourceID="SqlDataSourc
      AutoGenerateColumns="False
      <Columns>
       <asp:CommandField ShowSelectButton="True" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/images/d
         <HeaderStyle Wrap="False" CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" />
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
       </asp:CommandField>
       <asp:BoundField DataField="equipmenttype" HeaderText="TYPE" SortExpression="equipmentt
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="make" HeaderText="MAKE" SortExpression="make" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="model" HeaderText="MODEL" SortExpression="model" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="owner" HeaderText="OWNER" SortExpression="owner" >
         <ItemStyle HorizontalAlign="Left" Wrap="False" />
         <HeaderStyle CssClass="headertitle" Font-Size="Small" HorizontalAlign="Left" Wrap="False" />
      Â
       </asp:BoundField>
      </Columns>
       <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
       <AlternatingRowStyle CssClass="Tdatagray" />
         <EditRowStyle BackColor="#999999" />
         <RowStyle CssClass="tdatasilva" />
       <HeaderStyle Font-Size="X-Small" Font-Names="Tahoma" />
     </asp:GridView>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BamAdmin
      SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([equipmenttype] = @equipmenttype)"
      DeleteCommand="DELETE FROM [hardwareinventory] WHERE [id] = @id">
      <SelectParameters>
       <asp:ControlParameter ControlID="DropDownList1" Name="equipmenttype" PropertyName="SelectedValu
        Type="String" />
      </SelectParameters>
     </asp:SqlDataSource>
     <asp:HyperLink ID="HyperLink1" ImageUrl="~/images/add.gif
     <asp:HyperLink ID="HyperLink2" ImageUrl="~/images/delete.
    </td>
    <td valign="top" style="width: 225px; height: 309px;">
     <asp:DetailsView AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSourc
      HeaderText="<b>EQUIPMENT DETAILS</b>" CssClass="headertitle" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView
      <Fields>
       <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" InsertVisible="False" >
         <ItemStyle CssClass="box_title" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
         <HeaderStyle CssClass="tdatagray" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="make" HeaderText="make" SortExpression="make" >
         <ItemStyle CssClass="box_title" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
         <HeaderStyle CssClass="tdatagray" HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
       </asp:BoundField>
       <asp:BoundField DataField="model" HeaderText="model" SortExpression="model" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="serial" HeaderText="serial" SortExpression="serial" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="owner" HeaderText="owner" SortExpression="owner" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" >
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmentt
         <ItemStyle CssClass="box_title" />
         <HeaderStyle CssClass="tdatagray" />
       </asp:BoundField>
       <asp:CommandField ButtonType="Image" EditImageUrl="~/images/doc
              ShowEditButton="True" ShowInsertButton="True">
         <HeaderStyle CssClass="tdata" />
         <ItemStyle CssClass="tdata" />
       </asp:CommandField>
      </Fields>
       <HeaderStyle Font-Size="XX-Small" />
     </asp:DetailsView>
     <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:BamAdmin
      SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([id] = @id)"
      UpdateCommand="UPDATE [hardwareinventory] SET [equipmenttype] = @equipmenttype, [make] = @make, [model] = @model, [serial] = @serial, [owner] = @owner, [name] = @name WHERE [id] = @id"
      InsertCommand="INSERT INTO [hardwareinventory] ([equipmenttype], [make], [model], [serial], [owner], [name]) VALUES (@equipmenttype, @make, @model, @serial, @owner, @name)">
      <SelectParameters>
       <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValu
        Type="String" />
      </SelectParameters>
      <UpdateParameters>
       <asp:Parameter Name="equipmenttype" Type="String" />
       <asp:Parameter Name="make" Type="String" />
       <asp:Parameter Name="model" Type="String" />
       <asp:Parameter Name="serial" Type="String" />
       <asp:Parameter Name="owner" Type="String" />
       <asp:Parameter Name="name" Type="String" />
       <asp:Parameter Name="id" Type="String" />
      </UpdateParameters>
      <InsertParameters>
       <asp:Parameter Name="make" Type="String" />
       <asp:Parameter Name="model" Type="String" />
       <asp:Parameter Name="serial" Type="String" />
       <asp:Parameter Name="owner" Type="String" />
       <asp:Parameter Name="name" Type="String" />
       <asp:Parameter Name="equipmenttype" Type="String" />
      </InsertParameters>
     </asp:SqlDataSource>
    </td>
   </tr>
  </table>
  <br />
  <asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" />
 </form>
</body>
</html>
ASKER
Yes that sounds right. Currently we can do that but we have to click on a hyperlink that redirects to an insert page.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You did confuse me but thats not hard to do.
Lets say I am the user surfing the site now. You want me to be able to click on a link to open DetailsViewInsert.aspx and just start adding a new records without having to click on anything else? or am I missing something here?