Gridview Linkbutton-- to Export excel [Resolved]

Posted by Sivaprasadadiraju under ASP.NET on 11/9/2010 | Points: 10 | Views : 5650 | Status : [Member] | Replies : 6
Hi,
i have a gridview with all emp details. here emp name is in link button. when i click on emp name(linkbutton) details of employee
will export into excel means one excel sheet has to be open. Here what happening is that page is in updatepanel so
that linkbutton losing viewstate. but i need updatepanel .let me know how to solve this

SIVA PRASAD ADIRAJU


Responses

Posted by: Madhuk on: 11/10/2010 [Member] Starter | Points: 50

Up
0
Down

Resolved
Spent some time and this worked for me according to your requirement.
<asp:PostBackTrigger ControlID="LinkButton1" />

give controlid as Id of any control( may be hidden) which is out of gridview.

write the following code on row created event.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

{
LinkButton lnk = e.Row.FindControl("LinkButton1") as LinkButton;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (lnk != null)
{

ScriptManager1.RegisterPostBackControl(lnk);
}
//PostBackTrigger pb = new PostBackTrigger();
//pb.ControlID = lnk.UniqueID;
}
}

Mark as answer if it helped you.

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhuk on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
When using inside the update panel you need to create a postback trigger with control id of the linkButton.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<Triggers>
<asp:PostBackTrigger ControlID="LinkButton1" />
</Triggers>
</asp:UpdatePanel>

Hope this helps.

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sivaprasadadiraju on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Maduk,
i implemented this thing also but its not working

my linkbutton in ItemTemplate ..

Updatepanel-->Gridview-->Itemtemplate-->LinkButton this is the scenario Here its not identifying linkbutton to create
triggers what you told

SIVA PRASAD ADIRAJU

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sivaprasadadiraju on: 11/11/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Madhuk ,

Thank you very much its working...Actually i didnt add Scripmanager explicitly its Ajax webform.. i had written as follows

LinkButton lnk = gvMFDWise.FindControl("lnkbtn") as LinkButton;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (lnk != null)
{
ScriptManager scriptManager2 = ToolkitScriptManager.GetCurrent(Page);
scriptManager2.RegisterPostBackControl(lnk);
}

}

Really nice responce from you..!!

SIVA PRASAD ADIRAJU

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhuk on: 11/11/2010 [Member] Starter | Points: 25

Up
0
Down
most welcome.

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response