link button in dynamically created grid view ???

Posted by Rajnish Singh under ASP.NET on 1/20/2013 | Points: 10 | Views : 4567 | Status : [Member] | Replies : 3
hello respected expert,

please please help me .Actually I have created dynamic gridview on button click Now I am in serious trouble I add link button in row databound but does not able to fire the link button click event .Please help me. please tell me the steps to do this .Is I have to give any code in page load please help

thanxxx




Responses

Posted by: Kundnani.Rt on: 1/20/2013 [Member] Starter | Points: 25

Up
0
Down
Please clarify in brief about your problem with LinkButton.

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

Posted by: Senishant on: 1/20/2013 [Member] Starter | Points: 25

Up
0
Down
when gridview container hold the button, then you have to find that control if you want to use any click event

<asp:GridView ID="GridView1" runat="server" DataKeyNames="empno"
AutoGenerateColumns="false" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Employee no">
<itemtemplate>
<asp:LinkButton CommandName="cmdBind" runat="server" Text='<%#Eval("empno")%>' ID="hypeno" ToolTip='<%#Eval("empno")%>'>LinkButton
</asp:LinkButton>
</itemtemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Employee Name" DataField="empname" />
<asp:BoundField HeaderText="Employee Salary" DataField="Salary" />
</Columns>
</asp:GridView>

Server Side Code

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdBind")
{
LinkButton lb = (LinkButton)e.CommandSource;

Response.Redirect("GridHypher2.aspx?eno=" + lb.Text + "");
}

}
Hope this Will Help You!

www.TechnologyBrunch.com
www.geekblogtips.com

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

Posted by: Rajnish Singh on: 1/20/2013 [Member] Starter | Points: 25

Up
0
Down
thanks for reply sir,

Actually in my website I create gridview dynamically using this code

GridView gv = new GridView();



gv.ID = gvv;
gv.AutoGenerateColumns = true;
gv.AllowPaging = true;
gv.EnableViewState = true;

gv.DataSource = DS;

PlaceHolder1.Controls.Add(gv);
gv.AutoGenerateEditButton = true;
gv.DataBind();



Now i Want to fire the grid view events..
I got success to handle the row data-bound using this code

  gv.RowDataBound += new GridViewRowEventHandler(inventoryGridView_RowDataBound);


it successfully work but now I have two problem.
first is when I fire row editing and row updating and row command events. then these events never get fired.
second is when I place link button in grid view I am not able to fire the link button click event .
when I click on link button grid view got invisible I think it is postback problem.
please help me......



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

Login to post response