2014-09-19 218 views
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"; 
      } 
    } 

任何帮助,将不胜感激

谢谢请

+0

什么“操作离子“不会发射? – mxmissile 2014-09-19 17:15:54

+0

保护无效GridView1_Databound&保护无效GridView1_RowDataBound 我的意思是他们可能是,我有他们的代码完全错误,但我不能看到如何/为什么... – Zooch84 2014-09-19 17:17:55

+0

你忘了注册的事件:'RowDataBound =“GridView1_RowDataBound” ' – Andrei 2014-09-19 17:35:39

回答

1

你需要线了违规事件:

<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" 
    OnRowDataBound="GridView1_RowDataBound" 
    OnDataBound="GridView1_Databound"> 
+0

非常感谢。凌晨3点半,大脑并没有运转起来。 – Zooch84 2014-09-20 04:24:23