Note that there are some explanatory texts on larger screens.

plurals
  1. POSelected row GridView won't extract data
    primarykey
    data
    text
    <p>I have a GridView which I am filling with data from my database. The data displays perfectly. My problem is that I want to be able to click on a row and then display the information that is in that row elsewhere (eventually I'll have a splitscreen to format the selected data nicely). The selection works, because it highlights the current row. However, I cannot figure out how to display that data elsewhere. For now, I'm trying to display the content of a single cell in a label called testLabel. I've tried many different methods, and the testLabel never updates when I click a new row. Can anybody see what is going wrong here?</p> <p>C#</p> <pre><code>protected void DefaultGrid_SelectedIndexChanged(Object sender, EventArgs e) { GridViewRow row = DefaultGrid.SelectedRow; testLabel.Text = row.Cells[2].Text; } </code></pre> <p>ASPX</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager ID = "ScriptManager" runat="server" /&gt; &lt;div&gt; &lt;div&gt; &lt;asp:Label runat="server" id = "orderByLabel" Text = "Order By: " /&gt; &lt;asp:DropDownList runat="server" ID="orderByList" AutoPostBack="true"&gt; &lt;asp:ListItem Value="fName" Selected="True"&gt;First Name&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="lName"&gt;Last Name&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="state"&gt;State&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="zip"&gt;Zip Code&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="cwaSource"&gt;Source&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="cwaJoined"&gt;Date Joined&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Label runat="server" ID="searchLabel" Text="Search For: " /&gt; &lt;asp:TextBox ID="searchTextBox" runat="server" Columns="30" /&gt; &lt;asp:Button ID="searchButton" runat="server" Text="Search" /&gt; &lt;/div&gt; &lt;div align="center"&gt; &lt;asp:UpdatePanel ID = "up" runat="server"&gt; &lt;Triggers&gt; &lt;asp:AsyncPostBackTrigger ControlID = "orderByList" EventName="SelectedIndexChanged" /&gt; &lt;asp:AsyncPostBackTrigger ControlId="searchButton" EventName="Click" /&gt; &lt;/Triggers&gt; &lt;ContentTemplate&gt; &lt;asp:GridView ID="DefaultGrid" runat = "server" DataKeyNames = "fName" onselectedindexchanged = "DefaultGrid_SelectedIndexChanged" autogenerateselectbutton = "true" selectedindex="0"&gt; &lt;SelectedRowStyle BackColor="Azure" forecolor="Black" font-bold="true" /&gt; &lt;Columns&gt; &lt;asp:ButtonField CommandName="Select" Visible="false" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Label runat="server" ID="testLabel" Text="test" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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.
    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