Forms C#Web表单:显示MessageBox时GridView消失
我有3个GridView,每个都在一个单独的选项卡中。GridView中的每一行都与一个LinkButton相关联,当单击它时,会弹出一个MessageBox,显示该特定行上的内容 问题是,当MessageBox弹出时,GridView消失,当MessageBox关闭时,GridView返回 如果在没有任何选项卡的情况下使用GridView,并且将其放置在TabControl之外,则不会出现此问题。这是我的密码:Forms C#Web表单:显示MessageBox时GridView消失,forms,gridview,web,tabs,Forms,Gridview,Web,Tabs,我有3个GridView,每个都在一个单独的选项卡中。GridView中的每一行都与一个LinkButton相关联,当单击它时,会弹出一个MessageBox,显示该特定行上的内容 问题是,当MessageBox弹出时,GridView消失,当MessageBox关闭时,GridView返回 如果在没有任何选项卡的情况下使用GridView,并且将其放置在TabControl之外,则不会出现此问题。这是我的密码: protected void Page_Load(object sender, E
protected void Page_Load(object sender, EventArgs e)
{
TabControl TheTabCtrl = new TabControl("InfoTabCtrl");
for (var i = 0; i < 3; i++)
{
GridView newGridView = new GridView();
//generate dynamic id
newGridView.ID = String.Concat("GridView", i);
newGridView.AutoGenerateColumns = false;
newGridView.RowDataBound += new GridViewRowEventHandler(OnRowDataBound);
//if (!this.IsPostBack)
//{
BoundField bfield = new BoundField();
bfield.HeaderText = "Id";
bfield.DataField = "Id";
newGridView.Columns.Add(bfield);
bfield = new BoundField();
bfield.HeaderText = "Name";
bfield.DataField = "Name";
newGridView.Columns.Add(bfield);
TemplateField tfield = new TemplateField();
tfield.HeaderText = "Country";
newGridView.Columns.Add(tfield);
tfield = new TemplateField();
tfield.HeaderText = "View";
newGridView.Columns.Add(tfield);
//}
this.BindGrid(newGridView, i);
string myString = i.ToString();
TabPage BasicPage1 = new TabPage(myString, myString);
BasicPage1.Controls.Add(newGridView);
TheTabCtrl.Tabs.Add(BasicPage1);
}
if (!this.IsPostBack)
{
string value = Request.Form[TheTabCtrl.Id + "_SelectedTab"];
if (!string.IsNullOrEmpty(value))
{
try
{
TheTabCtrl.SelectedTab = TheTabCtrl.Tabs.IndexOf(TheTabCtrl.Tabs.Where(x => x.Id == value).First());
}
catch
{
}
}
}
form1.Controls.Add(TheTabCtrl.GetControl);
}
private void BindGrid(GridView newGridView, int id)
{
string[][,] jaggedArray = new string[3][,]
{
new string[,] { {"John Hammond", "United States"}, {"Mudassar Khan", "India"}, {"Suzanne Mathews", "France"}, {"Robert Schidner", "Russia"} },
new string[,] { {"Zoey Melwick", "New Zeeland"}, {"Bryan Robertson", "England"}, {"Beth Stewart", "Australia"}, {"Amanda Rodrigues", "Portugal"} },
new string[,] { {"Glenda Becker", "Germany"}, {"Despoina Athanasiadis", "Greece"}, {"Alexandra López", "Spain"}, {"David Bouchard", "Canada"} }
};
for (int row = 0; row < jaggedArray.Length; row++)
{
if (id != row) continue;
DataTable dt = new DataTable();
// Share the same headlines
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
for (int pair = 0; pair < jaggedArray[row].Length / 2; pair++)
{
dt.Rows.Add(pair + 1, jaggedArray[row][pair, 0], jaggedArray[row][pair, 1]);
}
string myPage = string.Concat(row, "page");
string myString = row.ToString();
newGridView.DataSource = dt;
newGridView.DataBind();
}//End for Row
}//BindGrid
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtCountry = new TextBox();
txtCountry.ID = "txtCountry";
txtCountry.Text = (e.Row.DataItem as DataRowView).Row["Country"].ToString();
e.Row.Cells[1].Width = 200;
e.Row.Cells[2].Controls.Add(txtCountry);
LinkButton lnkView = new LinkButton();
lnkView.ID = "lnkView";
lnkView.Text = "View";
lnkView.Click += ViewDetails;
lnkView.CommandArgument = (e.Row.DataItem as DataRowView).Row["Id"].ToString();
e.Row.Cells[3].Controls.Add(lnkView);
}
}
protected void ViewDetails(object sender, EventArgs e)
{
LinkButton lnkView = (sender as LinkButton);
GridViewRow row = (lnkView.NamingContainer as GridViewRow);
string id = lnkView.CommandArgument;
string name = row.Cells[1].Text;
string country = (row.FindControl("txtCountry") as TextBox).Text;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Id: " + id + " Name: " + name + " Country: " + country + "')", true);
}
受保护的无效页面加载(对象发送方,事件参数e)
{
TabControl TheTabCtrl=新TabControl(“InfoTabCtrl”);
对于(变量i=0;i<3;i++)
{
GridView newGridView=新GridView();
//生成动态id
newGridView.ID=String.Concat(“GridView”,i);
newGridView.AutoGenerateColumns=false;
newGridView.RowDataBound+=新的GridViewRowEventHandler(OnRowDataBound);
//如果(!this.IsPostBack)
//{
BoundField bfield=新的BoundField();
bfield.HeaderText=“Id”;
bfield.DataField=“Id”;
newGridView.Columns.Add(bfield);
bfield=新的BoundField();
bfield.HeaderText=“Name”;
bfield.DataField=“Name”;
newGridView.Columns.Add(bfield);
TemplateField tfield=新TemplateField();
tfield.HeaderText=“国家”;
newGridView.Columns.Add(tfield);
t字段=新模板字段();
tfield.HeaderText=“查看”;
newGridView.Columns.Add(tfield);
//}
这个.BindGrid(newGridView,i);
字符串myString=i.ToString();
TabPage BasicPage1=新TabPage(myString,myString);
BasicPage1.Controls.Add(newGridView);
tabCtrl.Tabs.Add(基本页面1);
}
如果(!this.IsPostBack)
{
字符串值=Request.Form[TheTabCtrl.Id+“_SelectedTab”];
如果(!string.IsNullOrEmpty(值))
{
尝试
{
TheTabCtrl.SelectedTab=TheTabCtrl.Tabs.IndexOf(TheTabCtrl.Tabs.Where(x=>x.Id==value.First());
}
抓住
{
}
}
}
form1.Controls.Add(TheTabCtrl.GetControl);
}
私有void BindGrid(GridView newGridView,int-id)
{
字符串[][,]jaggedArray=新字符串[3][,]
{
新字符串[,]{“约翰·哈蒙德”、“美国”}、{“穆达萨·汗”、“印度”}、{“苏珊娜·马修斯”、“法国”}、{“罗伯特·希德纳”、“俄罗斯”},
新字符串[,]{“Zoey Melwick”,“new Zeeland”},{“Bryan Robertson”,“英格兰”},{“Beth Stewart”,“澳大利亚”},{“Amanda Rodrigues”,“葡萄牙”},
新字符串[,]{“Glenda Becker”、“Germany”}、{“Despoina Athanasiadis”、“Greece”}、{“Alexandra López”、“Spain”}、{“David Bouchard”、“Canada”}
};
for(int row=0;row
那么,如何在不消失GridView的情况下显示MessageBox呢