i like Chaaraan solution. If you like, you can manuplate it on code behind as well. Please see below
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
' It is first column in your dataTable, so its index is ZERO
e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(1)
End If
End Sub
Chaaraan's solution did not show any errors before building but once running it errors and bolds "auto generate field = false" so i am not sure what to do with this to make it work. it means that i have one template column and the others are boundfields.
again i have tried your solution mezzanine74 but cannot get it to work.
can you show me please the Select Command of "SqlDataSource2"? If your data source produce a, b, c, d prefixes, our solutions should work.
SELECT [Job Information Table].JobNo, [Tasks Table].OutlineTaskDesc, [Tasks Table].SubTaskDesc, [Tasks Table].ActualStartDate, [Tasks Table].ActualFinishDate, [Tasks Table].Comments, [Job Information Table].Customer, [Job Information Table].DateRecd, [Job
Information Table].ProjStartDate, [Job Information Table].ProjFinishDate, [Job Information Table].PrjType, [Job Information Table].StatusSummary, [Job Information Table].[Project Workspace], [Job Information Table].[Business Case], [Job Information Table].UserReqs,
[Job Information Table].Assumptions, [Job Information Table].AdditionalInfo, [Job Information Table].[Project Handover Notes], [Job Information Table].Comments AS Expr1, [Resource Names Table].[Resource Name], [Resource Names Table].[Full Name] FROM (([Job
Information Table] INNER JOIN [Tasks Table] ON [Job Information Table].JobNo = [Tasks Table].JobNo) INNER JOIN [Resource Names Table] ON [Tasks Table].ResourceName = [Resource Names Table].[Resource Name]) WHERE ([Job Information Table].JobNo = ?)
lenovo1
Member
3 Points
36 Posts
Removing First Character - Gridview.
Nov 12, 2012 11:27 AM|LINK
i have a gridiew set up and data is pulled from an access database. I ordered a list of items in the dropdown using a,b,c,d.
So the problem is that now the gridview is displaying the below and i want to remove a,b,c from the start of the options.
i have tried many different ways but cant get the gridview to change. any help would be appreciated.
aEXAMPLE
bEXAMPLE2
cEXAMPLE3
mezzanine74
Contributor
2480 Points
730 Posts
Re: Removing First Character - Gridview.
Nov 12, 2012 11:35 AM|LINK
This string function will trim first letter of ant string
MID(YourText,2,LEN(YourText)-1)
lenovo1
Member
3 Points
36 Posts
Re: Removing First Character - Gridview.
Nov 12, 2012 11:47 AM|LINK
where is the best place to put this?
within the gridview dataformat?, or .cs page?, asp:boundfield tags for each column?
mezzanine74
Contributor
2480 Points
730 Posts
Re: Removing First Character - Gridview.
Nov 12, 2012 12:16 PM|LINK
you may use RowDataBound event of Gridview. Can you please show me your ASPX page where this column appears?
lenovo1
Member
3 Points
36 Posts
Re: Removing First Character - Gridview.
Nov 12, 2012 01:24 PM|LINK
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource2" ForeColor="#333333"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="OutlineTaskDesc" HeaderText="Outline Task Description"
SortExpression="OutlineTaskDesc" />
<asp:BoundField DataField="SubTaskDesc" HeaderText="Sub Task Description"
SortExpression="SubTaskDesc" />
<asp:BoundField DataField="ActualFinishDate" dataformatstring="{0:dd-MM-yyyy}"
HeaderText="Completed Date" SortExpression="ActualFinishDate" />
<asp:BoundField DataField="Full Name" HeaderText="Full Name"
SortExpression="Full Name" />
<asp:BoundField DataField="Comments" HeaderText="Comments"
SortExpression="Comments" />
</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" />
</asp:GridView>
in bold is the column, i could try and get a snap shot to put in here aswell.
Task | sub task | completed date |
aEXAMPLE | example | example|
bEXAMPLE | example | example
chaaraan
Contributor
2170 Points
484 Posts
Re: Removing First Character - Gridview.
Nov 12, 2012 03:04 PM|LINK
Hi,
Replace the bolded part(i.e., first column) with an Item Template to do string formatting like this
<asp:TemplateField HeaderText="Outline Task Description" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<%# Eval("OutlineTaskDesc").ToString().Substring(1) %>
</ItemTemplate>
</asp:TemplateField>
Regards,
Charan
mezzanine74
Contributor
2480 Points
730 Posts
Re: Removing First Character - Gridview.
Nov 13, 2012 05:00 AM|LINK
i like Chaaraan solution. If you like, you can manuplate it on code behind as well. Please see below
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then ' It is first column in your dataTable, so its index is ZERO e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(1) End If End Sublenovo1
Member
3 Points
36 Posts
Re: Removing First Character - Gridview.
Nov 13, 2012 09:17 AM|LINK
thank you for the replies.
Chaaraan's solution did not show any errors before building but once running it errors and bolds "auto generate field = false" so i am not sure what to do with this to make it work. it means that i have one template column and the others are boundfields.
again i have tried your solution mezzanine74 but cannot get it to work.
anymore advise or solutions?
mezzanine74
Contributor
2480 Points
730 Posts
Re: Removing First Character - Gridview.
Nov 13, 2012 10:57 AM|LINK
can you show me please the Select Command of "SqlDataSource2"? If your data source produce a, b, c, d prefixes, our solutions should work.
lenovo1
Member
3 Points
36 Posts
Re: Removing First Character - Gridview.
Nov 13, 2012 11:07 AM|LINK
SELECT [Job Information Table].JobNo, [Tasks Table].OutlineTaskDesc, [Tasks Table].SubTaskDesc, [Tasks Table].ActualStartDate, [Tasks Table].ActualFinishDate, [Tasks Table].Comments, [Job Information Table].Customer, [Job Information Table].DateRecd, [Job Information Table].ProjStartDate, [Job Information Table].ProjFinishDate, [Job Information Table].PrjType, [Job Information Table].StatusSummary, [Job Information Table].[Project Workspace], [Job Information Table].[Business Case], [Job Information Table].UserReqs, [Job Information Table].Assumptions, [Job Information Table].AdditionalInfo, [Job Information Table].[Project Handover Notes], [Job Information Table].Comments AS Expr1, [Resource Names Table].[Resource Name], [Resource Names Table].[Full Name] FROM (([Job Information Table] INNER JOIN [Tasks Table] ON [Job Information Table].JobNo = [Tasks Table].JobNo) INNER JOIN [Resource Names Table] ON [Tasks Table].ResourceName = [Resource Names Table].[Resource Name]) WHERE ([Job Information Table].JobNo = ?)