Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way to hide rows in 1.1 datagrid? 2

Status
Not open for further replies.

clanm

Programmer
Dec 26, 2005
237
US
When I click "Edit" on a row in a 1.1 datagrid, is there a way to set all the other rows to Visible=False or something along those lines. I'd like to hide all other rows. I don't want to post to another page for the edit since there are multiple filters on this page.

In the edit command for the datagrid I'm trying to do following, but no luck:

DataGrid1.EditItemIndex = e.Item.ItemIndex
If DataGrid1.EditItemIndex <> e.Item.ItemIndex Then
DataGrid1.ItemStyle.....something
End If

I've tried setting the font or height, but it's not making a difference.
 
You could loop through each row and assign the row a CSS class depending on whether it should be shown or not (The CSS class to hide the row would just contain "display:hide").


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I have this in the datagrid's ItemCommand handler, but no luck either.

DataGrid1.EditItemIndex = e.Item.ItemIndex

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.Item Then

If DataGrid1.EditItemIndex <> e.Item.ItemIndex Then

e.Item.Visible = False

End If

End If

'...code that builds datgrid

Call BuildDG()
 
Tried this in Itemdatabound, but no luck still:

If e.Item.ItemType = ListItemType.EditItem Then
If DataGrid1.EditItemIndex <> e.Item.ItemIndex Then
e.Item.Visible = False
End If
End IF
 
just wondering why you would want to hide a row? if your trying to hide rows based on records, why not exclude those records in your sql?

just a thought

 
I did try this in the ItemDataBound, but no luck:

If DataGrid1.EditItemIndex <> e.Item.ItemIndex Then
DataGrid1.ItemStyle.CssClass = "hide"
End If

...in the style sheet:
.hide
{
visibility: hidden;
display: none;
}
 
dvannoy,

If a user clicks on a row, let's say the last one on each datagrid page, the browser goes to the top of the page. Then, the user has to scroll back down to the bottom of the page to edit the row. I know this will get annoying for users, and we'll start getting complaints. If I take the "Edit" to another page, I'll have to keep some type of session for the filters we have, along with the page number.

My datagrid has a custom EditItemTemplate, which seems to create some weird functionality.....like editing the first record on the 2nd page causes the DeleteCommand to fire....I have no idea why!!!!!!! When the user clicks "Edit", we show a dropdownlist, 4 text boxes, and an AJAX autocomplete text box.
 
you have more issues then just trying to hide a row.

if you want to hold your page position you can use tags or there are third party controls that do that.

or, you can look into SmartNavigation.. but I myself would not use SmartNavigation. there are other issues with that.



also, post your html for your grid.
 
dvannoy,

here's the HTML:

<asp:datagrid id="DataGrid1" runat="server" Font-Size="X-Small" BackColor="White" Width="1100px"
Height="16px" OnPageIndexChanged="DataGridPaging" PageSize="12" BorderColor="#CCCCCC" AllowPaging="True"
cellPadding="3" AutoGenerateColumns="False" BorderStyle="None" BorderWidth="1px">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
<EditItemStyle Font-Size="XX-Small"></EditItemStyle>
<ItemStyle Height="25px" ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Size="8pt" Font-Bold="True" Height="15px" ForeColor="White" BackColor="#006699"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Chk Code">
<HeaderStyle HorizontalAlign="Center" Width="20px"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id=CheckBox1 runat="server" Width="20px" Height="16px" Checked='<%# DataBinder.Eval(Container, "DataItem.Check") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle Width="30px"></ItemStyle>
<ItemTemplate>
<asp:LinkButton id="Linkbutton1" runat="server" Text="Edit" NAME="Linkbutton1"
CausesValidation="false" CommandName="Edit">
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton id="Linkbutton2" runat="server" Text="Update" NAME="Linkbutton2" CommandName="Update"></asp:LinkButton>&nbsp;
<asp:LinkButton id="Linkbutton3" runat="server" Text="Cancel" NAME="Linkbutton3" CausesValidation="false"
CommandName="Cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<HeaderStyle Width="20px"></HeaderStyle>
<ItemStyle Font-Size="8pt"></ItemStyle>
</asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderStyle Width="20px"></HeaderStyle>
<ItemTemplate>
<asp:HyperLink id=HyperLink1 runat="server" Font-Size="7pt" Text="Locate" NavigateUrl='<%# "ResLoc.aspx?id=" &amp; DataBinder.Eval(Container, "DataItem.UniqueIdentifier") &amp; "&amp;SAID=" &amp; lblSAID.Text.Tostring %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>' width="130px">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<TABLE id="Table2" style="WIDTH: 496px; HEIGHT: 206px" cellSpacing="1" cellPadding="1" width="496" border="1">
<TR>
<TD>
<asp:TextBox id="TextBox5" runat="server" Width="100px" Enabled="False">Name:</asp:TextBox></TD>
<TD>
<CUSTOM:AUTOSUGGESTBOX id="txtPerson" tabIndex="3" runat="server" Width="400px" MaxLength="100" MaxSuggestChars="20"
IncludeMoreMenuItem="True" DataType="Person" CssClass="FormCtrl" Columns="30" ResourcesDir="/WPC/asb_includes"></CUSTOM:AUTOSUGGESTBOX>
</TD>
<TD align="left">
<asp:Image id="Image1" onmouseover="ddrivetip('Begin entering as many characters as possible for last name, use the space bar when last name is complete, then begin typing first name in textbox to the left. Complete last name and/or first name is not required but will help build a more consice dropdown list. Dropdown list will momentarily show available names starting with letters entered. Click name for selection!', 250)"
onmouseout="hideddrivetip()" runat="server" BackColor="Transparent" EnableViewState="False"
ImageUrl="images\question_mark_30x30.png"></asp:Image></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox7" runat="server" Width="100px" Enabled="False">P3Activity ID:</asp:TextBox>
</TD>
<TD>
<CUSTOM:AUTOSUGGESTBOX id=castxtP3ActID tabIndex=3 runat="server" Width="400px" AutoPostBack="True" Text='<%# DataBinder.Eval(Container, "DataItem.P3ActivityId") %>' MaxLength="100" MaxSuggestChars="20" IncludeMoreMenuItem="True" DataType="ActID" CssClass="FormCtrl" Columns="30" ResourcesDir="/WPC/asb_includes">
</CUSTOM:AUTOSUGGESTBOX>
<asp:RequiredFieldValidator id="rfvP3ActID" runat="server" Font-Size="X-Small" ErrorMessage="* P3Activity ID required!" ControlToValidate="castxtP3ActID" display="None"></asp:RequiredFieldValidator>
</TD>
<TD align="left">
<asp:Image id="Image3" onmouseover="ddrivetip('Begin entering the Activity ID in the text box to the left. A dropdown list will momentarily show available IDs starting with characters entered. These IDs have been entered in the Activities section when editing existing work package information. Click ID for selection!', 250)"
onmouseout="hideddrivetip()" runat="server" BackColor="Transparent" EnableViewState="False"
ImageUrl="images\question_mark_30x30.png"></asp:Image>
</TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox8" runat="server" Width="100px" Enabled="False">Resource Code:</asp:TextBox></TD>
<TD>
<CUSTOM:AUTOSUGGESTBOX id="txtRes" tabIndex="4" runat="server" Width="400px" MaxLength="100" MaxSuggestChars="20"
IncludeMoreMenuItem="True" DataType="Res" CssClass="FormCtrl" Columns="30" ResourcesDir="/WPC/asb_includes"></CUSTOM:AUTOSUGGESTBOX>
<asp:RequiredFieldValidator id="rfvResCode" runat="server" Font-Size="X-Small" CssClass="ValSum" ErrorMessage="* Resource Code required!"
ControlToValidate="txtRes" display="None"></asp:RequiredFieldValidator></TD>
<TD align="left">
<asp:Image id="Image2" onmouseover="ddrivetip('Begin entering as many characters as possible for P3E Resource Code in textbox to the left. Full P3E Resource Code is not required but will help build a more consice dropdown list. Dropdown list will momentarily show available codes starting with characters entered. Click code for selection!', 250)"
onmouseout="hideddrivetip()" runat="server" BackColor="Transparent" EnableViewState="False"
ImageUrl="images\question_mark_30x30.png"></asp:Image></TD>
</TR>
<TR>
<TD style="HEIGHT: 27px">
<asp:TextBox id="TextBox9" runat="server" Width="100px" Enabled="False">Rate Type:</asp:TextBox></TD>
<TD style="HEIGHT: 27px" colSpan="2">
<asp:DropDownList id=ddlRateType runat="server" Font-Size="10pt" Width="400px" DataValueField="ComboCode" DataTextField="RtCdCnct" DataSource="<%# GetRateType() %>">
</asp:DropDownList></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox10" runat="server" Width="100px" Enabled="False">Fiscal Year:</asp:TextBox></TD>
<TD colSpan="2">
<asp:TextBox id=Textbox3 runat="server" Font-Size="10pt" Width="400px" Text='<%# DataBinder.Eval(Container, "DataItem.FiscalYear") %>' MaxLength="2">
</asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox11" runat="server" Width="100px" Enabled="False">ReCharge:</asp:TextBox></TD>
<TD colSpan="2">
<asp:TextBox id=TextBox6 runat="server" Font-Size="10pt" Width="400px" Text='<%# DataBinder.Eval(Container, "DataItem.ReCharge") %>'>
</asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox12" runat="server" Width="100px" Enabled="False">Budget Qty:</asp:TextBox></TD>
<TD colSpan="2">
<asp:TextBox id=TextBox4 runat="server" Font-Size="10pt" Width="400px" Text='<%# DataBinder.Eval(Container, "DataItem.BudgetQuantity") %>'>
</asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="txtStatus" Width="100px" Enabled="False" Runat="server">Status:</asp:TextBox></TD>
<TD colSpan="2">
<asp:DropDownList id=ddlStatus runat="server" width="80px" DataValueField="Value" DataTextField="Key" SelectedIndex='<%# GetSelectedStatusIndex(Container.DataItem("Status")) %>' datasource="<%# GetStatus() %>">
</asp:DropDownList></TD>
</TR>
<TR>
<TD colSpan="3">
<asp:ValidationSummary id="valsumm1" runat="server" Font-Size="Small" width="400px" CssClass="ValSum" HeaderText="* Errors: "
DisplayMode="BulletList"></asp:ValidationSummary>
<asp:RangeValidator id="RangeValidator2" runat="server" ErrorMessage="Budget Quantity must be 0 or greater!"
ControlToValidate="TextBox4" Type="Double" MinimumValue="0" MaximumValue="1000000" Display="None"></asp:RangeValidator><BR>
<asp:Label id="lblResCodeWarn" runat="server" Font-Size="X-Small" ForeColor="Red"></asp:Label><BR>
<asp:Label id="lblNameWarning" runat="server" Font-Size="X-Small" ForeColor="Red"></asp:Label>
<asp:Label id="lblBudgetQtyWarning" runat="server" Font-Size="X-Small" ForeColor="Red"></asp:Label></TD>
</TR>
</TABLE>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Z#">
<ItemTemplate>
<asp:Label id=Label13 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.Number") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ActId">
<ItemTemplate>
<asp:Label id=Label2 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.Act") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Resource Code">
<HeaderTemplate>
<asp:Label id="LabelResCode" runat="server" Width="60px">Res Code</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=Label7 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.ResCode") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Rate Type">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<HeaderTemplate>
<asp:Label id="Label5" runat="server" Width="25px">Rate Type</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=Label4 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.RateType") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Resource Type">
<ItemTemplate>
<asp:Label id=Label10 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.ResourceType") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<HeaderTemplate>
<asp:Label id="Label3" runat="server">FY</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="Label6" runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.FY") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ReChrg">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label id=Label12 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.ReCharge") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Budget Qty">
<HeaderStyle HorizontalAlign="Right" Width="50px"></HeaderStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:Label id="Label8" runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.BQ") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Qty Type">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<HeaderTemplate>
<asp:Label id="Label14" runat="server" Width="25px">Qty Type</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=Label9 runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.QT") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Total Qty">
<HeaderStyle HorizontalAlign="Right" Width="60px"></HeaderStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:Label id="Label11" Font-Size="8pt" runat="server" Width="60" Text='<%# DataBinder.Eval(Container, "DataItem.TQ", "{0:c}") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="UniqueIdentifier" ReadOnly="True" HeaderText="UniqueIdentifier"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Sts">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center">
</ItemStyle>
<ItemTemplate>
<asp:Label id="lblResStatus" runat="server" Font-Size="8pt" Text='<%# DataBinder.Eval(Container, "DataItem.Status") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle NextPageText="Next" Height="15px" PrevPageText="Prev" HorizontalAlign="Left" ForeColor="#000066"
BackColor="White" PageButtonCount="20" Mode="NumericPages">
</PagerStyle>
</asp:datagrid>
 
Here is how I set focus on an EditItem in a DataGrid

Code:
    protected void dgItems_Edit(Object sender, DataGridCommandEventArgs e)
    {
        dgItems.EditItemIndex = e.Item.ItemIndex;
        BindData(GetPageName());

        TextBox tDesc = (TextBox)dgItems.Items[e.Item.ItemIndex].Cells[3].FindControl("txtDescription");
        //Type controlType = tDesc.GetType();
        //Set the script to focus and select the TextBox
        try
        {
            BusinessFunctions.SetFocus(tDesc);

        }
        catch (Exception ex)
        {

        }

    }

BusinessFunctions.SetFocus
Code:
    public static void SetFocus(System.Web.UI.Control control)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append("\r\n<script language='JavaScript'>\r\n");
        sb.Append("<!--\r\n");
        sb.Append("function SetFocus()\r\n");
        sb.Append("{\r\n");
        sb.Append("\tdocument.");

        System.Web.UI.Control p = control.Parent;

        while (!(p is System.Web.UI.HtmlControls.HtmlForm)) p = p.Parent;

        sb.Append(p.ClientID);
        sb.Append("['");
        sb.Append(control.UniqueID);
        sb.Append("'].focus();\r\n");
        sb.Append("}\r\n");
        sb.Append("window.onload = SetFocus;\r\n");
        sb.Append("// -->\r\n");
        sb.Append("</script>");


        control.Page.ClientScript.RegisterClientScriptBlock(control.GetType(), "SetFocus", sb.ToString());
    }


HTH

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top