參考網址、參考網址
母視窗GridView按下查詢,跳出新視窗選取值後送回母視窗特定地方的GridView
母視窗
GridView類型
母視窗前台
<asp:TemplateField >
<ItemTemplate>
<asp:TextBox ID="tbxSearchResult" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="SearchAll"/>
</ItemTemplate>
</asp:TemplateField>
母視窗後台
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var tbxSearchResult = e.Row.FindControl("tbxSearchResult") as TextBox;
if (tbxSearchResult != null)
{
var domId = tbxSearchResult.ClientID;
var btn = e.Row.FindControl("btnSearch") as Button;
if (btn != null)
{
var js = string.Format(@"window.open('..//SearchAllPeople.aspx?type=name&id={0}');return false;", domId);
btn.OnClientClick = js;
}
}
}
}
無GridView類型
母視窗前台
<asp:TextBox ID="tbxSearchResult" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="查找SearchAll" CssClass="ThreeP_4word" OnClick="btnSearch_Click" OnClientClick="window.open('..//SearchAllPeople.aspx?type=name&id={0}');return false;" />
母視窗無後台
子視窗有GridView
子視窗前台
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="false" AllowPaging="false" OnRowCommand="gvData_RowCommand"
EmptyDataText="查無資料">
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="選取"></asp:CommandField>
<asp:BoundField HeaderText="No" DataField="NO" />
<asp:BoundField HeaderText="Name" DataField="Name" />
</Columns>
</asp:GridView>
<asp:Label ID="lblTeaNo" runat="server"></asp:Label>
子視窗後台
protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToString() == "Select" || e.CommandName.ToString()=="選取")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = this.gvData.Rows[index];
lblTeaNo.Text = row.Cells[1].Text ;
//彈出的數值對不對
//Javascript.Alert("選取" + row.Cells[2].Text);
//父頁面有GridView
if (QueryString("id", String.Empty) != null && QueryString("id", String.Empty) != "")
{
if (QueryString("type", String.Empty) != "name" )
{
//傳TeaNo
this.Page.Controls.Add(new LiteralControl(string.Format("<script>opener.document.getElementById('{0}').value ='{1}'</script>",QueryString("id", String.Empty) , lblTeaNo.Text)));
}else
{
//傳名字
this.Page.Controls.Add(new LiteralControl(string.Format("<script>opener.document.getElementById('{0}').value ='{1}'</script>", QueryString("id", String.Empty), row.Cells[2].Text)));
}
//關閉此視窗
this.Page.Controls.Add(new LiteralControl("<script>window.close();</script>"));
}
else
{
////傳值給父頁面
this.Page.Controls.Add(new LiteralControl(string.Format("<script>opener.document.getElementById('ctl00_ContentPlaceHolder1_TextBox1').value ='{0}'</script>", lblTeaNo.Text)));
//關閉此視窗
this.Page.Controls.Add(new LiteralControl("<script>window.close();</script>"));
}
}
}
沒有留言:
張貼留言