1
沒有錯誤,但是我的設置方式是,GridView在Page_Load上呈現,看起來似乎是我設置的其餘操作似乎沒有觸發。GridView操作順序
訂單上的任何想法?它一直是小時了:(
<asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True" EmptyDataText="No Records Found" AutoGenerateColumns="False" DataSourceID="showOrders" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Height="74px" Width="394px">
<Columns>
<asp:TemplateField HeaderText ="Pizza Type" SortExpression="pizza_id">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("pizza_id") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="mylabel" runat="server" Text='<%#Bind("pizza_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="quantity" HeaderText="Quanity" SortExpression="quantity" />
<asp:BoundField DataField="pizza_size" HeaderText="Pizza Size" SortExpression="pizza_size" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:SqlDataSource ID="showOrders" runat="server" ConnectionString="<%$ ConnectionStrings:Database %>"></asp:SqlDataSource>
代碼背後:。
public partial class order_details : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
string username = User.Identity.Name;
showOrders.SelectParameters.Add("username", username);
showOrders.SelectCommand = "SELECT [pizza_id], [quantity], [pizza_size] FROM [orders] WHERE ([username][email protected])";
}
protected void GridView1_Databound(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
row.Visible = row.RowIndex.Equals(1);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
string value = e.Row.Cells[7].Text;
Label myLabel = (Label) e.Row.FindControl("myLabel");
if (value == "1")
{
myLabel.Text = "Big Cheese";
}
else if (value == "2")
{
myLabel.Text = "BBQ Beef";
}
else if (value == "3")
{
myLabel.Text = "Chicken and Pineapple";
}
else if (value == "4")
{
myLabel.Text = "Pepperoni Feast";
}
else if (value == "5")
{
myLabel.Text = "Vegetarian";
}
}
任何幫助,將不勝感激
謝謝請
什麼「操作離子「不會發射? – mxmissile 2014-09-19 17:15:54
保護無效GridView1_Databound&保護無效GridView1_RowDataBound 我的意思是他們可能是,我有他們的代碼完全錯誤,但我不能看到如何/爲什麼... – Zooch84 2014-09-19 17:17:55
你忘了註冊的事件:'RowDataBound =「GridView1_RowDataBound」 ' – Andrei 2014-09-19 17:35:39