问题
I have a GridView with several BoundFields from a compact SQL database (I am using the older Visual Studio Express 2010, in C#)
I am experimenting, and have read that if your GridView fields are BoundFields rather than Template, extraction of the value should be as easy as:
Label.Text = GridView1.SelectedRow.Cells[0].Text;
(considering you are aiming for the value of the selected row)
I am trying to show that value in a Modal Popup Extender, and it's showing blank. No error message at all, and the debugger just shows the value blank all the time. Since I am quite a beginner, I am guessing that probably my error is in the placement of the parts, but I couldn't figure it out:
My GridView definition has this:
onselectedindexchanged="GridView1_SelectedIndexChanged"
Then later on I have a Panel with a Modal Popup Extender:
<asp:Panel ID="view" runat="server" CssClass="pnlBackGround">
<asp:Label ID="vid" runat="server" ></asp:Label>
<asp:Button ID="vclose" runat="server" Text="Cerrar" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender2"
PopupControlID="view"
OkControlID="vclose"
TargetControlID="f1"
BackgroundCssClass="modalBackground"
runat="server">
</ajaxToolkit:ModalPopupExtender>
And the function that is giving me problems is the one called on selected index changed:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
vid.Text = GridView1.SelectedRow.Cells[0].Text;
this.ModalPopupExtender2.Show();
}
I think that this code should grab the value of the first cell of the selected row, and place it as text of the "vid" label, and then open the popup extender with that information.
What (probably silly) thing am I doing wrong?
来源:https://stackoverflow.com/questions/30673256/cannot-set-label-text-values-in-a-modal-popup-from-gridview-values-in-boundfiel