0

Here is a gridview from ASPX page (abbreviated):

<asp:gridview ID="Gridview1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView_RowCommand" DataKeyNames="order_no" onrowdatabound="Gridview1_RowDataBound" AllowPaging="false" >
            <Columns>
                <asp:HyperLinkField DataTextField="order_no" HeaderText="Order Number" ItemStyle-Font-Bold="true" /><asp:HyperLinkField />
                <asp:BoundField DataField="id_number" HeaderText="Customer ID"  ItemStyle-Font-Bold="true" />
             </Columns>
        </asp:gridview> 

The ASPX page has a textbox with a label "Enter Customer ID" and a Button. When user enters a text and clicks the button, I want in the code behind find the value of Order_no.

Hidalgo
  • 941
  • 2
  • 14
  • 38
  • Is there a way you can do what you need on the aspx page? Like maybe using an itemtemplate? – DeadlyChambers Dec 14 '15 at 16:30
  • @DeadlyChambers I don't know what and how to use itemtemplate. I will look for it. Thank you. – Hidalgo Dec 14 '15 at 16:33
  • Find the value of _Order_no_ as in? What is relation? How is customer id (entered by the user) is associated with order_no in gridview? – Rahul Singh Dec 14 '15 at 17:12
  • @RahulSingh Both customer ID and Order No come from a db table. User views all values of ID and Order No in the Grid View. But, for a business reason, the user may want to, instead of scrolling the grid view, enter the Custom ID and in the code behind redirect the page based on the Order No of the corresponding customer ID. – Hidalgo Dec 14 '15 at 17:16
  • @Hidalgo - Okay and when you are setting the `NavigateUrl` property of your _HyperLinkField_? – Rahul Singh Dec 14 '15 at 17:19
  • @RahulSingh the property of NavigateUrl is set in the Grid View. I simple removed it from the post, to make it smaller and simpler. The user can click on the URL if he chooses but sometimes may want to go to an item by entering text and the button. – Hidalgo Dec 14 '15 at 17:22
  • @Hidalgo - But still are you binding in code behing or in aspx page with `Eval`? Also what is `DataTextField` attribute? Is that a custom attribute? – Rahul Singh Dec 14 '15 at 17:28
  • If I may ask a simple question, please. Can someone show me the code that I would use in the code behind to get the value in the column "id_number" for row 0 (zero). If only reference in code behind is the ID of the Grid Viiew (Gridview1). What is the syntax? – Hidalgo Dec 14 '15 at 18:44

1 Answers1

0

You might be looking for something like this

 <asp:gridview ID="Gridview1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView_RowCommand" DataKeyNames="order_no" onrowdatabound="Gridview1_RowDataBound" AllowPaging="false" >
        <Columns>
           <asp:TemplateField >
            <ItemTemplate>
                <%# (Eval("order_no") > 0 ? "<a href="AnotherPage.aspx?OrderNo=Eval("order_no")">Something</a>" : "") %>
            </ItemTemplate>
            </asp:TemplateField>   
            <asp:BoundField DataField="id_number" HeaderText="Customer ID"  ItemStyle-Font-Bold="true" />
          </Columns>
        </asp:gridview>
DeadlyChambers
  • 5,217
  • 4
  • 44
  • 61
  • I don't understand how the above created itemtemplate would help me in my initial question. – Hidalgo Dec 14 '15 at 16:39
  • What are you trying to do with order_no when they click the button. Do you actually NEED to go back to the server? – DeadlyChambers Dec 14 '15 at 16:43
  • Based on the value of order_no I need to redirect to another page, using the order_no as a parameter. For example: Response.Redirect("AnotherPage.aspx?OrderNo="+ OrderNo, true); – Hidalgo Dec 14 '15 at 16:48
  • Check the answer edit or try use this post http://stackoverflow.com/questions/5743099/looping-through-gridview-rows-and-checking-checkbox-control – DeadlyChambers Dec 14 '15 at 16:52
  • 1
    I did find and read the post you have referenced. I just don't understand how to apply it to my case. I will need to re-read and study more. Thank you. – Hidalgo Dec 14 '15 at 16:55
  • And thank for the answer edit. I still don't get it how it works. As I said in my initial post, there is a textbox and a button on the page where user enters the ID (e.g. Customer ID). I don't see where this textbox is references in your answer code. – Hidalgo Dec 14 '15 at 17:00
  • So the user is going to enter a customer id, then push a button? Why don't you just have a button on each row that will do the navigation for them? – DeadlyChambers Dec 14 '15 at 17:05
  • There is a business reason why the user has to enter the ID into the text box. Having buttons on each row is not in the business of this page. – Hidalgo Dec 14 '15 at 17:17