Datagrid Sorting

Discussion in 'ASP .Net Datagrid Control' started by Yama, Aug 12, 2004.

  1. Yama

    Yama Guest

    Hi,

    When trying to dynamically add the header column name in my datagrid I lose
    the sorting abilities.

    private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)

    {

    ListItemType itemType = e.Item.ItemType;

    if (e.Item.ItemType == ListItemType.Header )

    {

    e.Item.Cells[2].Text = "Employee"

    e.Item.Cells[3].Text = "Company Name"

    }

    }

    How can I give it back the sorting ability?



    Thanks,



    Yama
    Yama, Aug 12, 2004
    #1
    1. Advertising

  2. Yama

    Jos Guest

    Yama wrote:
    > Hi,
    >
    > When trying to dynamically add the header column name in my datagrid
    > I lose the sorting abilities.
    >
    > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
    >
    > {
    >
    > ListItemType itemType = e.Item.ItemType;
    >
    > if (e.Item.ItemType == ListItemType.Header )
    >
    > {
    >
    > e.Item.Cells[2].Text = "Employee"
    >
    > e.Item.Cells[3].Text = "Company Name"
    >
    > }
    >
    > }
    >
    > How can I give it back the sorting ability?


    Try this to change the header text:

    grd.Columns[2].HeaderText = "Employee";
    grd.Columns[3].HeaderText = "Company Name";

    --

    Jos
    Jos, Aug 13, 2004
    #2
    1. Advertising

  3. Yama

    Yama Guest

    Hello Jos,

    You da man! Thanks that worked.

    Yama




    "Jos" <> wrote in message
    news:...
    > Yama wrote:
    > > Hi,
    > >
    > > When trying to dynamically add the header column name in my datagrid
    > > I lose the sorting abilities.
    > >
    > > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
    > >
    > > {
    > >
    > > ListItemType itemType = e.Item.ItemType;
    > >
    > > if (e.Item.ItemType == ListItemType.Header )
    > >
    > > {
    > >
    > > e.Item.Cells[2].Text = "Employee"
    > >
    > > e.Item.Cells[3].Text = "Company Name"
    > >
    > > }
    > >
    > > }
    > >
    > > How can I give it back the sorting ability?

    >
    > Try this to change the header text:
    >
    > grd.Columns[2].HeaderText = "Employee";
    > grd.Columns[3].HeaderText = "Company Name";
    >
    > --
    >
    > Jos
    >
    >
    Yama, Aug 13, 2004
    #3
  4. Yama

    Yama Guest

    Jos,

    Do you happen to know also how I could change the header text of an header
    template:

    <Columns>
    <asp:TemplateColumn HeaderText="Select">
    <HeaderTemplate>
    <asp:checkbox id="chkDeleteAll"
    onclick="javascript:SelectAllCheckboxes(this);" runat="server"
    TextAlign="Left" Text="Select All" ToolTip="Select/Deselect All"
    AutoPostBack="false"></asp:checkbox>
    </HeaderTemplate>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ITEMTEMPLATE>
    <asp:CheckBox id="chkDelete"
    onclick="javascript:HighlightRow(this);" runat="server"
    AutoPostBack="false"></asp:CheckBox>
    </ITEMTEMPLATE>
    </asp:TemplateColumn>
    </Columns>

    How can I change the Text="Select All" dynamically? I am using the resource
    file to globalize my web apps.

    Thanks,

    Yama




    "Jos" <> wrote in message
    news:...
    > Yama wrote:
    > > Hi,
    > >
    > > When trying to dynamically add the header column name in my datagrid
    > > I lose the sorting abilities.
    > >
    > > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
    > >
    > > {
    > >
    > > ListItemType itemType = e.Item.ItemType;
    > >
    > > if (e.Item.ItemType == ListItemType.Header )
    > >
    > > {
    > >
    > > e.Item.Cells[2].Text = "Employee"
    > >
    > > e.Item.Cells[3].Text = "Company Name"
    > >
    > > }
    > >
    > > }
    > >
    > > How can I give it back the sorting ability?

    >
    > Try this to change the header text:
    >
    > grd.Columns[2].HeaderText = "Employee";
    > grd.Columns[3].HeaderText = "Company Name";
    >
    > --
    >
    > Jos
    >
    >
    Yama, Aug 13, 2004
    #4
  5. Yama

    Jos Guest

    Yama wrote:
    > Jos,
    >
    > Do you happen to know also how I could change the header text of an
    > header template:
    >
    > <Columns>
    > <asp:TemplateColumn HeaderText="Select">
    > <HeaderTemplate>
    > <asp:checkbox id="chkDeleteAll"
    > onclick="javascript:SelectAllCheckboxes(this);" runat="server"
    > TextAlign="Left" Text="Select All"
    > ToolTip="Select/Deselect All" AutoPostBack="false"></asp:checkbox>
    > </HeaderTemplate>
    > <ItemStyle HorizontalAlign="Center"></ItemStyle>
    > <ITEMTEMPLATE>
    > <asp:CheckBox id="chkDelete"
    > onclick="javascript:HighlightRow(this);" runat="server"
    > AutoPostBack="false"></asp:CheckBox>
    > </ITEMTEMPLATE>
    > </asp:TemplateColumn>
    > </Columns>
    >
    > How can I change the Text="Select All" dynamically? I am using the
    > resource file to globalize my web apps.


    For this, you can use the ItemDataBound event handler.

    Try:
    (CheckBox)e.Item.FindControl("chkDeleteAll").Text="new text";

    --

    Jos
    Jos, Aug 13, 2004
    #5
  6. Yama

    Yama Guest

    Hi Jos,

    the Text property doesn't exist... Any way to grab it and set it in another
    context?

    I tried the following in the Item DataBound:
    CheckBox chk = (CheckBox)e.Item.FindControl("chkDeleteAll");
    chk.Text = "New Test";

    But I got an error that the object wasn't referenced...

    Any suggestions?

    Yama



    "Jos" <> wrote in message
    news:...
    > Yama wrote:
    > > Jos,
    > >
    > > Do you happen to know also how I could change the header text of an
    > > header template:
    > >
    > > <Columns>
    > > <asp:TemplateColumn HeaderText="Select">
    > > <HeaderTemplate>
    > > <asp:checkbox id="chkDeleteAll"
    > > onclick="javascript:SelectAllCheckboxes(this);" runat="server"
    > > TextAlign="Left" Text="Select All"
    > > ToolTip="Select/Deselect All" AutoPostBack="false"></asp:checkbox>
    > > </HeaderTemplate>
    > > <ItemStyle HorizontalAlign="Center"></ItemStyle>
    > > <ITEMTEMPLATE>
    > > <asp:CheckBox id="chkDelete"
    > > onclick="javascript:HighlightRow(this);" runat="server"
    > > AutoPostBack="false"></asp:CheckBox>
    > > </ITEMTEMPLATE>
    > > </asp:TemplateColumn>
    > > </Columns>
    > >
    > > How can I change the Text="Select All" dynamically? I am using the
    > > resource file to globalize my web apps.

    >
    > For this, you can use the ItemDataBound event handler.
    >
    > Try:
    > (CheckBox)e.Item.FindControl("chkDeleteAll").Text="new text";
    >
    > --
    >
    > Jos
    >
    >
    Yama, Aug 13, 2004
    #6
  7. Yama

    Jos Guest

    Yama wrote:
    > Hi Jos,
    >
    > the Text property doesn't exist... Any way to grab it and set it in
    > another context?
    >
    > I tried the following in the Item DataBound:
    > CheckBox chk = (CheckBox)e.Item.FindControl("chkDeleteAll");
    > chk.Text = "New Test";
    >
    > But I got an error that the object wasn't referenced...


    You're still using the condition:

    if (e.Item.ItemType == ListItemType.Header )

    aren't you?

    --

    Jos
    Jos, Aug 14, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,422
    James Kanze
    Jul 6, 2010
  2. AlainCD
    Replies:
    0
    Views:
    202
    AlainCD
    Jan 12, 2006
  3. Jason
    Replies:
    0
    Views:
    380
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    472
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    156
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page