Click here to Skip to main content
15,120,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a linkbutton that is suppose to passes a value to a textbox,the textbox and the linkbutton are both inside a gridview . When i click the linkbutton a popup extender is executed with my textbox. Now i tried to find the textbox but stil its empty.

How can i do this?

Below is my gridview

<asp:GridView  ID="grdAvailableStaff"  runat="server"  CellPadding="4"  EnableViewState="true"
               Width="423px" onrowdatabound="grdAvailableStaff_RowCreated"
               ForeColor="#333333" GridLines="None" Height="16px" DataKeyNames="FullName"

                EmptyDataText="No Appointment Slots Created" >

               <AlternatingRowStyle BackColor="White" />

               <Columns >

              <asp:TemplateField HeaderText="Create Appointment">

                <asp:LinkButton ID="createAppointment" runat="server"  OnClick="createAppointment_Click" PostBackUrl='<%# "frmFindAppointment.aspx?Fullname=" + HttpUtility.UrlEncode(Eval("Fullname").ToString())+"&RecordNumber="+ HttpUtility.UrlEncode(Eval("RecordNumber").ToString())+"&Date="+  HttpUtility.UrlEncode(Eval("Date").ToString())+"&SlotID="+ HttpUtility.UrlEncode(Eval("SlotID").ToString())+"&Timeslot="+ HttpUtility.UrlEncode(Eval("Timeslot").ToString())  %>' Text="Create Appointment" />
            <ajaxToolkit:ModalPopupExtender  BackgroundCssClass="modalBackground" ID="ModalPopupExtender1" runat="server" TargetControlID="createAppointment" PopupControlID="PNL" OkControlID="ButtonOk"  />

     <asp:Panel ID="PNL" runat="server" style="display:none; width:900px; background-color:White; border-width:2px; border-color:Black; border-style:solid; padding:20px;">
<asp:TextBox ID="txtViewPatientEmail" runat="server" 
                    ForeColor="Black" CssClass="textbox" ReadOnly="True"></asp:TextBox>


Below is how I reciev the passed values from my linkbutton

if (Request.QueryString["FullName"] != null && !string.IsNullOrEmpty(Request.QueryString["FullName"].ToString())
              || (Request.QueryString["Slots"] != null && !string.IsNullOrEmpty(Request.QueryString["Slots"].ToString()) || (Request.QueryString["SlotsID"] != null && !string.IsNullOrEmpty(Request.QueryString["SlotsID"].ToString()))))
                string SlotId = Convert.ToString((Request.QueryString["SlotsID"]));
                Session["SlotID"] = SlotId;

                string fullName = Convert.ToString((Request.QueryString["FullName"]));
                Session["FullName"] = fullName;


Below is the event to populate the textbox in my popup

foreach (GridViewRow row in grdAvailableStaff.Rows)

                //Am looking for the control name "txtViewPatientEmail"
                string txtViewStaffName = ((System.Web.UI.WebControls.TextBox)row.FindControl("txtViewPatientEmail")).Text;
                txtViewStaffName = Session["FullName"].ToString();

Am expecting every time i click a link, a popup will appear with a value inside...
Updated 16-Aug-11 23:30pm
Herman<T>.Instance 17-Aug-11 4:19am
first: show your code. That helps us understand what you do

1 solution

in the onclick event of your button:

Button btn = (Button)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;

By using this code you have the gridview row in which the button was clicked.

TextBox myTextBox = (TextBox)row.FindControl("nameOfYourTextBoxHere");
if (myTextBox != null) // control is found)
     myTextBox.Text = "any text you wnat to place in the textbox";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900