我讀過幾十對這個問題的帖子,並嘗試所有這些,但沒有運氣,我不知道我缺少什麼,這是GridView控件代碼:LinkButton的點播,的onClick,RowCommand在網格視圖不點火
<asp:GridView ID="recentJobsGridView" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" Height="151px" Width="541px" Visible="False" AutoGenerateColumns="False"
PageSize="5" AllowPaging="True" OnPageIndexChanging="recentJobsGridView_PageIndexChanging"
DataKeyNames="orderItemId">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Order Date" Visible="true">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("orderItemId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Order Date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("orderDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QTY">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("QTY") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Length">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("length") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="wall">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("wall") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paper Composition">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("paperComposition") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btAdd" runat="server" OnCommand="btAdd_Command" Text="Add"
CommandArgument='<%# Container.DataItem %>' CommandName="Add"></asp:LinkButton>
</ItemTemplate>
</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" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
這裏是我結合網格視圖:
protected void custGridView_SelectedIndexChanged(object sender, EventArgs e)
{
if (custGridView.SelectedDataKey != null)
{
selectCustomer = (int)custGridView.SelectedDataKey.Value;
recentJobsGridView.Visible = true;
recentJobsGridView.DataSource = ViewDataSource(selectCustomer);
recentJobsGridView.DataBind();
}
}
,這是LinkButton的的代碼:
protected void btAdd_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Add")
{
StatusLbl.Text = "Hellooooooo";
}
}
我刪除了所有我只想顯示此消息但沒有響應 請幫助...
如果在頁面加載時沒有'!Ispostback',gridview中的事件不會觸發。 –
謝謝,但我已經在page_load – salRad
我有這個問題。我在Page_PreRender中綁定了網格的數據,需要在page_load中這樣做。 – Jono