我在Data Gridview中添加了动态LinkButton,它将带我进入C#asp.net中的新页面。首先,我从下拉列表控件中选择值。它将重新加载页面并在Gridview中显示数据。在Gridview中,每一行都有动态的Linkbutton。当我在gridview中单击“链接按钮”时,它不起作用,页面已重新加载,并且隐藏了链接按钮。
当在page_load方法上粘贴下拉代码时,我的代码正在工作。
最近7个小时以来,我一直在进行研究,查看了大多数答案,但是没有任何解决我问题的方法。
根据我的研究,我发现页面重新加载后LinkButton丢失是状态(我不确定)。
预先感谢...
using System;
using System.Web.UI.WebControls;
namespace aweFinalTTA.TTA.BatchReport
{
public partial class CenterBatchList : System.Web.UI.Page
{
protected aweFunctionNew aweApi = new aweFunctionNew();
protected aweCodePublic aweCode = new aweCodePublic();
protected LinkButton linkButton01;
protected GridView gdv;
protected DropDownList ddlTTCCode;
override protected void OnInit(EventArgs e)
{
aweApi.showForm(aweApi.getManageFieldDT("select * from manage_field where table_name='TTCBatchList'"), frmBatchList);
ddlTTCCode = (DropDownList)frmBatchList.FindControl(frmBatchList.ID + "ddlTTCCode");
ddlTTCCode.SelectedIndexChanged += new EventHandler(ddlTTCCode_SelectedIndexChanged);
frmBatchList.Controls.Add(aweApi.addGridViewNew("EmpGrid", "List of Batch Created"));
gdv = (GridView)frmBatchList.FindControl("EmpGrid");
gdv.RowDataBound += OnRowLinkBound;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
aweApi.getDDL(ddlTTCCode, "select TTCCode,TTCCode from TTCDetail where TTARNO='" + Session["TTARNO_01"].ToString() + "' and TTCDetail.TTCCode in (Select TTCCode from TTCCourseListOfTTC) and TTCDetail.TTCCode in (Select TTCCode from TTCInfraDetail) and TTCDetail.TTCCode in (Select TTCCode from TTCFacility) order by LastUpdatedDate desc", true);
TemplateField tfieldCheckbox = new TemplateField();
tfieldCheckbox.HeaderText = "Select";
gdv.Columns.Add(tfieldCheckbox);
}
}
protected void ddlTTCCode_SelectedIndexChanged(object sender, EventArgs e)
{
gdv.DataSource = aweApi.getResultsDT("select * from BatchMain where TTCCode='TTC0000002008'");
gdv.DataBind();
gdv.HeaderRow.TableSection = TableRowSection.TableHeader;
}
protected void OnRowLinkBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton linkButton = new LinkButton();
linkButton.ID = "link";
linkButton.Text = "Edit";
linkButton.ForeColor = System.Drawing.Color.Blue;
linkButton.Click += linkButton_Click;
e.Row.Cells[0].Controls.Add(linkButton);
}
}
protected void linkButton_Click(object sender, EventArgs e)
{
// GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
/// Session["TTCBatchId_01"] = gr.Cells[2].Text.Trim(); /*For first cell value of Row */
Response.Write("linkbutton_click is working");
aweCode.showMessage(this, "aaaaaa");
//Response.Redirect("~/TTA/BatchReport/BatchAddCandidate");
}
}
}