Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double click in a gridview 1

Status
Not open for further replies.

technisup

Programmer
Sep 28, 2007
41
US
I have a Gridview and when customer clicks in a row should send the values (for instance, the ID and the Company's name)to a new aspx page. How can i do this?

Thx for the help.
 
you need to configure the row (or cells) to execute javascript on double click. using window.href="newpage.aspx?id=<%#Eval("Id")%>"

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
As we are talking about objects, do you have any example of it?
Thx
 
use google to find example of double clicking table rows. then google registering client scripts from code behind. this should give you the pieces you need.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I found a way to do it:

Code:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">
    
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

        Select Case e.CommandName

            Case "Select"

                GridView1.SelectedIndex = e.CommandArgument
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            
                ' Retrieve the row that contains the button clicked 
                ' by the user from the Rows collection.
                Dim row As GridViewRow = GridView1.Rows(index)
            
                ' Create a new ListItem object for the customer in the row.     
                Dim Laciudad, Idciudad As String
                Laciudad = Server.HtmlDecode(row.Cells(2).Text)
                Idciudad = Server.HtmlDecode(row.Cells(1).Text)
                Response.Redirect("Propuesta_p2.aspx?laciudad='" & Laciudad & "'&idciudad='" & Idciudad & "'")

        End Select

    End Sub

</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <br />
    <img src="Images/PrimerPaso.png" style="position: static" /><br />
    <br />
    <br />
    <span style="font-size: 11pt; font-family: Tahoma">Seleccione el prospecto al cual desea
                    generar la consulta:</span><br />
    <br />
    <br />
    <center>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" DataKeyNames="IdCiudad" DataSourceID="SqlDataSource1"
        Style="position: static">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="IdCiudad" HeaderText="IdCiudad" InsertVisible="False"
                ReadOnly="True" SortExpression="IdCiudad" />
            <asp:BoundField DataField="Descripcion" HeaderText="Descripcion" SortExpression="Descripcion" />
        </Columns>
    </asp:GridView>
    &nbsp;<br />
    &nbsp;<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>"
        DeleteCommand="DELETE FROM [Ciudad] WHERE [IdCiudad] = @IdCiudad" InsertCommand="INSERT INTO [Ciudad] ([Descripcion]) VALUES (@Descripcion)"
        SelectCommand="SELECT * FROM [Ciudad]" UpdateCommand="UPDATE [Ciudad] SET [Descripcion] = @Descripcion WHERE [IdCiudad] = @IdCiudad">
        <DeleteParameters>
            <asp:Parameter Name="IdCiudad" Type="Int16" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Descripcion" Type="String" />
            <asp:Parameter Name="IdCiudad" Type="Int16" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Descripcion" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    </center>
</asp:Content>


I'm really thankful with you for your posts and patience.
 
this works if the user clicks the button, not the row. I say this because your original requirement was to click the row. not sure if your users will mind the difference.

You repeat the key with both the datakey and an column. You only need one or the other. (I would recommend the datakey and drop the column). use MyGridView.DataKeys[e.Row.RowIndex]["Idciudad"] to get the key value.

if you're passing the id in the query string why are you also passing the description? just pass the id and query the db on the next page to get the description.

your using a SqlDataSource. This is bad (any and all datasources are bad). very, very bad.
1. they are impossible to debug
2. they promote poor/bad/horrendous coding (if you call mark up coding) habits.
3. the markup and code behind are presentation centric and shouldn't know about data access. instead the page should call a service to request the data. this service would then either (1) call the database to get the data or (2) ask a repository object to get the data.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I really appreciate your patience and is valid your suggestion but I'm new at this and I'm in ongoing learning step-by-step process, the thing here is that the deadline to deliver is really close and there're things that I need to learn.
 
understood, we all have a deadline and a boss. A word of caution, if this reason is continually used, then your skills will never advance. And maintenance will be difficult.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top