ASP.NET - how to enable panel ,when i click on Gridview Linkbutton(View button is placed in Grid)

Asked By aileni giri on 29-Jun-12 06:58 AM
Earn up to 10 extra points for answering this tough question.
<table >
<tr>
<td>
<asp:GridView  ID="gridview1" runat="server">
  <asp:TemplateField HeaderText="View">
         <ItemTemplate>
         <asp:LinkButton ID="lnkview"  Text="View" runat="server"></asp:LinkButton>
         </ItemTemplate>
       </asp:TemplateField>
         
       <asp:TemplateField HeaderText="Doc's">
         <ItemTemplate>
         <asp:LinkButton ID="lnkdocs"  Text="Doc's" runat="server"></asp:LinkButton>
         </ItemTemplate>
       </asp:TemplateField>
       </Columns>
       </asp:GridView>
</td>
</tr>
<tr>
<td>

</td>
</tr>
dipa ahuja replied to aileni giri on 29-Jun-12 07:46 AM
Add linkButton in itemTEmplate:
 
<ItemTemplate>
<asp:LinkButton ID="lnkd" CommandName="Select" runat="server" Text="Select" />
</ItemTemplate>
 
Then implement the RowCommand EVent:
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == "Select")
  {
    //Enable panel
   panel1.Enable= true;
  }
}
 
 
Chintan Vaghela replied to aileni giri on 29-Jun-12 08:19 AM

Hi Frndz,

 

Functionality:  GridView Link button click enable Panel

 

 

To achieve this task,

 

First you need to Added OnClick event of Link button

 

            <asp:LinkButton ID="lnkview" Text="View" runat="server" OnClick="lnkView_Click"></asp:LinkButton>

 

 

After added Server Side onclick Event

 

protected void lnkView_Click(Object sender, EventArgs e)

    {

    }

 

If  Panel OutSide GridView then Use

 

protected void lnkView_Click(Object sender, EventArgs e)

    {

      pnlView.Enabled = true;

    }

 

 

If  Panel Inside GridView then Use

 

protected void lnkView_Click(Object sender, EventArgs e)

    {

      LinkButton lnk = sender as LinkButton;

      GridViewRow grow = (GridViewRow)lnk.NamingContainer;

      Panel pnlInsideGridView = (Panel)grow.FindControl("pnlInsideGridView");

      pnlInsideGridView.Enabled = true;

  

    }

 

 

 

 

 

Full Logic with Inside Panel and Outside Gridview Panel Enabled:

 

Aspx PAGE

 

 

<asp:TemplateField HeaderText="View">

          <ItemTemplate>

            <asp:LinkButton ID="lnkview" Text="View" runat="server" OnClick="lnkView_Click"></asp:LinkButton>

          </ItemTemplate>

        </asp:TemplateField>

InSide

 

        <asp:TemplateField HeaderText="PanelView">

          <ItemTemplate>

            <asp:Panel ID="pnlInsideGridView" runat="server" Enabled="false">

              <asp:TextBox ID="txtViewName" runat="server"></asp:TextBox>

            </asp:Panel>

          </ItemTemplate>

        </asp:TemplateField>

 

 

OutSide

<asp:Panel ID="pnlView" runat="server" Enabled="false">

      <asp:TextBox ID="txtViewName" runat="server"></asp:TextBox>

    </asp:Panel>

 

CS PAGE

protected void lnkView_Click(Object sender, EventArgs e)

    {

      LinkButton lnk = sender as LinkButton;

      GridViewRow grow = (GridViewRow)lnk.NamingContainer;

      Panel pnlInsideGridView = (Panel)grow.FindControl("pnlInsideGridView");

      pnlInsideGridView.Enabled = true;

      pnlView.Enabled = true;

    }

 

 

Hope this helpful!

Thanks

 

 

 

Jitendra Faye replied to aileni giri on 29-Jun-12 08:20 AM
You can complete this task using client side code also-

use this code-

 <script type="text/javascript">
    function enable() {
        document.getElementById('<%=panel1.ClientID%>').disabled = false;
        return false;
      }
 </script>



          <ItemTemplate>
            <asp:LinkButton  ID="lnk" runat="server" Text="Enable" OnClientClick ="return enable();"/>
          </ItemTemplate>


Try this and let me know.
RAJASEKHAR RAJENDRAN replied to aileni giri on 29-Jun-12 08:40 AM
hi giri,

Hope the below link solves.

http://stackoverflow.com/questions/8798639/how-to-get-the-clicked-linkbutton-text-in-gridview-to-a-label-in-popup-panel 



Thanks & Regards,
Rajasekhar.R