當我在我的GridView
點擊,因爲我想重裝後看在這一個apears其他頁面更多成員的問題:http://i.gyazo.com/48e040f1d276984c0d3c6bfd8c38c974.pngASP.net - 我的用戶名多寫一次?
<form id="form1" runat="server">
<div>
<asp:Label ID="Label_welcome" runat="server" Text="Välkommen mr:"></asp:Label>
</div>
<asp:Button ID="B_logout" runat="server" OnClick="B_logout_Click" Text="Logga ut" />
<br />
<br />
<embed src="CV.pdf" width=1400px height=1000px >
<asp:SqlDataSource ID="SqlDataSourceRegister" runat="server" ConnectionString="<%$ ConnectionStrings:RegisterConnectionString %>" SelectCommand="SELECT * FROM [Table]"></asp:SqlDataSource>
</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSourceRegister" ForeColor="#333333" GridLines="None" Height="195px" Width="254px" DataKeyNames="Id" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="True" InsertVisible="False" />
<asp:BoundField DataField="Användarnamn" HeaderText="Användarnamn" SortExpression="Användarnamn" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Lösenord" HeaderText="Lösenord" SortExpression="Lösenord" />
<asp:BoundField DataField="Land" HeaderText="Land" SortExpression="Land" />
<asp:BoundField DataField="Fullnamn" HeaderText="Fullnamn" SortExpression="Fullnamn" />
<asp:TemplateField ShowHeader="False">
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br />
</form>
</div>
以上是我用的按鈕「N」代碼東西
public partial class _1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
Label_welcome.Text += Session["New"].ToString();
}
else
{
Response.Redirect("Login.aspx");
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("GridView1_SelectedIndexChanged");
}
protected void B_logout_Click(object sender, EventArgs e)
{
Session["New"] = null;
Response.Redirect("Login.aspx");
}
}
}
您需要發佈,實際上在文本'Label_welcome'填充代碼。我懷疑你正在做類似'Label_welcome.Text + = username;'這會導致雙重顯示,但是如果沒有看到代碼,我們就無法判斷。 – Rhumborl 2014-10-04 12:01:03
對不起,我更新了上面的代碼! – Wharruphomie 2014-10-04 12:08:42
我也有一個很好的選擇,會話數據沒有被正確保存,或者正在超時並在很短的時間間隔內被清除。 – shawty 2014-10-04 12:11:08