Datagrid Sorting

Y

Yama

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
 
J

Jos

Yama said:
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";
 
Y

Yama

Hello Jos,

You da man! Thanks that worked.

Yama




Jos said:
Yama said:
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";
 
Y

Yama

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 said:
Yama said:
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";
 
J

Jos

Yama said:
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";
 
Y

Yama

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
 
J

Jos

Yama said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top