C# 单击一次后,动态gridview上的动态链接按钮将消失 受保护的void gvCountryRisk_行数据绑定(对象发送方,GridViewRowEventArgs e) { int count=(int)ViewState[“count”]; 如果(e.Row.RowType==DataControlRowType.DataRow) { 对于(int i=1;i
这是因为C# 单击一次后,动态gridview上的动态链接按钮将消失 受保护的void gvCountryRisk_行数据绑定(对象发送方,GridViewRowEventArgs e) { int count=(int)ViewState[“count”]; 如果(e.Row.RowType==DataControlRowType.DataRow) { 对于(int i=1;i,c#,asp.net,gridview,C#,Asp.net,Gridview,这是因为链接按钮是在\rowdabund事件中添加的,它不会在链接按钮的回发时触发。请将绑定网格放在Ispostback检查的一侧。例如 <asp:GridView ID="gvCountryRisk" runat="server" SkinID="gridviewSkin" AllowPaging="false" OnRowDataBound="gvCountryRisk_RowDataBound">
链接按钮
是在\rowdabund
事件中添加的,它不会在链接按钮的回发时触发。请将绑定网格放在Ispostback
检查的一侧。例如
<asp:GridView ID="gvCountryRisk" runat="server" SkinID="gridviewSkin" AllowPaging="false"
OnRowDataBound="gvCountryRisk_RowDataBound">
</asp:GridView>
protected void gvCountryRisk_RowDataBound(object sender, GridViewRowEventArgs e)
{
int count = (int)ViewState["Count"];
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i <= count - 1; i++)
{
if (e.Row.Cells[i].Text != " ")
{
e.Row.Cells[i].Text = Convert.ToDouble(e.Row.Cells[i].Text).ToString("N2");
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
// ----------------dynamic link ----------------
LinkButton lnkView = new LinkButton();
lnkView.Text = e.Row.Cells[i].Text;
lnkView.CommandArgument = (e.Row.DataItem as DataRowView).Row[i].ToString();
string Country = gvCountryRisk.HeaderRow.Cells[i].Text;
string classfn = e.Row.Cells[0].Text;
ViewState["strClassification"] = classfn;
ViewState["strCounrty"] = Country;
int Month = Convert.ToInt16(ddlMonth.SelectedValue);
int Year = Convert.ToInt16(ddlYear.SelectedValue);
lnkView.Attributes.Add("onclick", "javascript:ShowDetails('" + Month + "','" + Year + "','" + Country + "','" + classfn + "')");
e.Row.Cells[i].Controls.Add(lnkView);
}
}
}
}
如果需要进一步的帮助,请提供网格数据源绑定方法。并公开其调用位置。您可以在rowdata绑定的cs页面中使用linkbutton属性,并调用jaavscript函数,该函数告诉您count和count大于1,以便您可以根据需要禁用此链接按钮…谢谢,但我希望gri上有linkbuttond对于每次单击,在第一次单击后,它不会出现在GridView上。请编写在ShowDetails函数中必须使用的代码。。。
protected void Page_Load(object sender, EventArgs e)
{
Bindgrid(); // Method to bind grid
if(!IsPostBack)
{
...
}
}