lookup page with a datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    lookup page with a datagrid

    Hello,

    I need help creating a lookup page which has a datagrid view.
    My firstpage.aspx has a textbox and button. When the button is clicked, it would open a pop-up page with a datagrid which has 2 columns in it. The user can select a row and the selected row's text should appear in the textbox of firstpage.aspx.

    I tried using javascript but unable to retrieve the value of the selected row. So can somebody help. I am using asp.net and C#.

    Thanks in advance.
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    PreviousPage Property

    Please go through the link below

    http://http://msdn.microsoft.com/en-.../ms178139.aspx

    What you'd like to do can be done through PreviousPage property.

    Comment

    • user1980
      New Member
      • Dec 2009
      • 112

      #3
      thank you sanjib for the response. i will look into it.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        You should be doing this using JavaScript (have to really).
        Why were you unable to retrieve the selected row?
        What did you try?

        -Frinny

        Comment

        • user1980
          New Member
          • Dec 2009
          • 112

          #5
          hello...i did go through the msdn link but am unable to use the findcontrol for my data grid.

          Frinny
          I was not able to get the GridView.Select edRow.Cells[1].Text value into my javascript. i can select the value and display it in the same page but do not know how can I pass that value to my javascript. I have a working javascript that would transfer the value to the first page. but passing the value of selected text is my problem.

          Code:
           function selectcode(code) {
                   if (window.opener && !window.opener.closed)
                   window.opener.document.form2.textbx.value = code;
                   window.close();
                   }
          this code now writes 'code' in my textbox, instead it should write the selected code say 1234 into my textbox.
          this is my gridview code
          Code:
          <asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False" 
               onselectedindexchanged="GridView_SelectedIndexChanged">
               <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
                <asp:BoundField DataField= "Name" HeaderText="Name" SortExpression="Name" />
               </Columns>
              
           </asp:GridView>
          i am unable to put my javascript in the code to retrieve the value of selected row.
          Please let me know if I am not clear. Thanks in advance.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            I Just posted a solution like this in another thread a day or so ago.
            Check out the JavaScript function I posted here:
            http://bytes.com/topic/asp-net/answe...ew#post3529043....

            -Frinny

            Comment

            • user1980
              New Member
              • Dec 2009
              • 112

              #7
              sorry, I am unable to figure out the solution for my problem using the javascript in that solution.
              I am using this code but no results
              Code:
              <asp:TemplateField HeaderText="Name">
                                  <ItemTemplate>
                                     <a style="cursor: hand" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'"
                                          name="Name" runat="server" onclick="javascript:selectcode(this)"
                                          id="Name">
                      <%# DataBinder.Eval(Container.DataItem, "Name") %>
                                      </a>
                      </ItemTemplate>
                                 </asp:TemplateField>

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                You could probably get a reference to the row using the element that is used to select the row.

                Right now you're passing that element to the "selectcode " method.

                Code:
                function selectcode(elementUsedToSelectRow)
                {
                }
                From here you need to retrieve the row. The row is a parent element of the element used to select the row...in fact it's the parent element of the parent element. You need to get a reference to the row that the element belongs to though so that you can loop through the cells and grab the information you need.

                I've moved this thread to the JavaScript forum.
                I think that they'll have a better idea how to do this than I do.

                -Frinny

                Comment

                • user1980
                  New Member
                  • Dec 2009
                  • 112

                  #9
                  thank you for the reply.

                  found the solution. i have to use #Eval('Name') to get the selected row index and that can be passed to javascript.

                  Comment

                  Working...