Как показать и скрыть поле кнопки в gridview, если строка содержит пустую ячейку
i have a gridview in my asp.net application. for example SN name Date Action 1 mike button(do something). This is just one out of my gridview rows. i want for every row that has an empty cell, button field cell for the row should show. if there's no empty cell in that row, the button should hide.What i get with my code is that all the button visible becomes false which i donot want.
Что я уже пробовал:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" Height="326px" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="5" style="text-align: left; margin-left: 169px" Width="1069px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowEditing="GridView1_RowEditing"> <Columns> <asp:BoundField HeaderText="S/N" DataField="SN" /> <asp:BoundField HeaderText="First Name" DataField="FirstName" /> <asp:BoundField HeaderText="Address" DataField="Address" /> <asp:BoundField HeaderText="Phone Number" DataField="PhoneNumber" /> <asp:BoundField HeaderText="Sex" DataField="Sex" /> <asp:BoundField HeaderText="Reason" DataField="Reason" /> <asp:BoundField HeaderText="SignIn" DataField="SignIn_Time" /> <asp:BoundField HeaderText="SignOut" DataField="Signout_Time" /> <asp:TemplateField HeaderText="Action" Visible="True"> <ItemTemplate> <asp:Button ID="out" runat="server" Text="Sign out" CommandName="SignOut" CommandArgument='<%#Eval("SN") %>' CssClass="active"/> </ItemTemplate> </asp:TemplateField> </Columns> <PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" PageButtonCount="5" />
с фоновым кодом
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { for (int i =0 ; i < e.Row.Cells.Count; i ++) { if (e.Row.Cells[i].Text == " ") { Button status = (Button)e.Row.FindControl("out"); status.Visible = true; } else { Button status = (Button)e.Row.FindControl("out"); status.Visible = false; } } } }