セッション変数を送信し、ページが変数を読み込み、セッション変数の文字列に基づいてデータを表示する別のページにリダイレクトするボタンがあります。それは動作しますが、ページを更新しないと表示されません。 ViewLeage.aspxためグリッドビューのデータは、ページをリフレッシュするまで表示されません。C#
protected void btnJoin_Click(object sender, EventArgs e)
{
Button lb = (Button)sender;
GridViewRow row = (GridViewRow)lb.NamingContainer;
getText1 = row.Cells[1].Text;
Session["showName"] = getText1;
Response.Redirect("ViewLeague.aspx");
}
とHERESにページのロード:HERESにボタンクリック
string SQLName = "SELECT teamname, draftedPlayer1, player1FP, draftedPlayer2, player2FP, draftedPlayer3, player3FP, draftedPlayer4, player4FP, totalFP FROM Drafted_Table WHERE LeagueName = '" + Name2 + " '";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (this.Session["showName"] != null)
{
Name2 = (String)this.Session["showName"];
}
}
EDIT:
相続人のデータがGridViewの
private void GetData()
{
DataTable table = new DataTable();
// get the connection
using (SqlConnection conn = new SqlConnection("Data Source= tyler-pc\\sqlexpress; Integrated Security=true; Database=CODFANTASY2"))
{
// write the sql statement to execute
string sql = SQLName;
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
// specify the data source for the GridView
ViewLeagueTable.DataSource = table;
// bind the data now
ViewLeagueTable.DataBind();
}
に追加されます
ご迷惑をおかけして申し訳ございません。私はここで見ている
まず、あなたが使用しています実際に何かを割り当てる前にSQLクエリの 'Name2'値を返します。 (注意:それを使用する方法もSQLインジェクションの脆弱性を示します)。したがって、この節は常にWHERE LeagueName = '' 'になります。第2に、 'ViewLeague.aspx'の' Page_Load'イベントは実際にユーザーにデータを表示しません。他のイベントがそれをしている場合、そのイベントがトリガーされるまで何も表示されません。 – David
データが追加される部分を追加します – user2993767
大変感謝しています。私はSQL文字列を移動する必要がありました – user2993767