Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would highly recommend using <code>TemplateField</code>s for all of your columns, like this:</p> <p>Markup:</p> <pre><code>&lt;Columns&gt; &lt;asp:TemplateField HeaderText="Account No" SortExpression="Agent_Account_No"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="LabelAccountNumber" runat="server" Text='&lt;%# Eval("Agent_Account_No") %&gt;'&gt; &lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; ... &lt;asp:TemplateField HeaderText="Name" SortExpression="Agent_Name"&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="AgentName" runat="server" Text='&lt;%# Eval("Agent_Name") %&gt;' CommandName="Select" CommandArgument='&lt;%#Bind("Agent_Name") %&gt;'&gt; &lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; </code></pre> <p>Now in the <code>RowCommand</code> method, you can use the <code>FindControl()</code> method of the grid view row to get to the text you are interested in, like this:</p> <p>Code-behind:</p> <pre><code>protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = GridView1.Rows[index]; // Find the account number label to get the text value for the text box Label theAccountNumberLabel = selectedRow.FindControl("LabelAccountNumber") as Label; // Make sure we found the label before we try to use it if(theAccountNumberLabel != null) { AccountNumber.Text = theAccountNumberLabel.Text; } // Follow the same pattern for the other labels to get other text values } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload