我有兩個鏈接一個動態的GridView button.if我按一下,如果我調用頁面「顯示」方法加載其工作罰款鏈接按鈕事件不firing.but。下面鏈接按鈕,在動態的GridView不費一槍在asp.net
public void display()
{
GridView grdv = new GridView();
grdv.AutoGenerateColumns = false;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
BL.ESSBL bl = new BL.ESSBL();
ds = bl.GetContactList();//getting datatable
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
dt = ds.Tables[0];
grdv.RowDataBound += new GridViewRowEventHandler(grdv_RowDataBound);
grdv.DataSource = null;
grdv.DataBind();
grdv.Columns.Clear();
for (int i = 0; i < dt.Columns.Count; i++)
{
BoundField boundfield = new BoundField();
boundfield.DataField = dt.Columns[i].ColumnName.ToString();
boundfield.HeaderText = dt.Columns[i].ColumnName.ToString();
grdv.Columns.Add(boundfield);
}
TemplateField tmf = new TemplateField();
grdv.Columns.Add(tmf);
tmf = new TemplateField();
grdv.Columns.Add(tmf);
grdv.DataSource = dt;
grdv.DataBind();
pnlupdate.Controls.Add(grdv);
}
}
void grdv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int count= e.Row.Cells.Count;
LinkButton lnkupdate= new LinkButton();
lnkupdate.ID = "Update";
lnkupdate.Text = "Update";
LinkButton lnkdelete = new LinkButton();
lnkdelete.ID = "delete";
lnkdelete.Text = "delete";
lnkdelete.Click += new EventHandler(lnkdelete_Click);
lnkupdate.CommandArgument = (e.Row.DataItem as DataRowView).Row[0].ToString();
lnkdelete.CommandArgument = (e.Row.DataItem as DataRowView).Row[0].ToString();
lnkupdate.Click += new EventHandler(lnkupdate_Click);
e.Row.Cells[count-2].Controls.Add(lnkupdate);
e.Row.Cells[count-1].Controls.Add(lnkdelete);
}
}
protected void ddlProcess_SelectedIndexChanged(object sender, EventArgs e)
{
dynamicgridview(); // not working
Clear();
}
void lnkupdate_Click(object sender, EventArgs e)
{
Response.Write(@"<script language=""javascript"">alert(""update details "");</script>");
}
如果我把
代碼頁「顯示」方法加載,它會調用每一個postback.i不希望這樣。我想打電話給在下拉選項更改事件此方法。如果我將「顯示」方法放入該鏈接點擊事件不會觸發。 所以我必須做的,以克服這一點。
如何加載您的'dropdownlist'並顯示您選擇的代碼更改事件。我認爲不處理回傳是實際問題。 – Hassan
@hassan我用dropdownlist更新了代碼,我不想在頁面load.is中調用顯示方法。 – nichu09
好吧,你是如何填充'ddlProcess'?如果我點擊GridView的鏈接按鈕不觸發其消失 – Hassan