473,659 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BoundColumn

A DataGrid has a BoundColumn which changes to a TextBox when the
DataGrid is in the editable mode. The rest of the columns in the
DataGrid are TemplateColumns . There's an EditCommandColu mn as well.
All the columns including the BoundColumn but excluding the
EditCommandColu mn can be sorted. The column sorted is also accompanied
by an image to indicate whether a column has been sorted ascendingly
or descendingly. The image gets rendered when the ItemDataBound event
of the DataGrid fires. This is the DataGrid:

<asp:DataGrid ID="dgCart"
OnEditCommand=" EditCart"...OnI temDataBound="B indCart" runat="server">

<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:LinkButt on ID="lnkPID" CommandArgument ="PID" Text="ID"
runat="server"/>&nbsp;<img id="imgPID" src="Up.gif" visible="false"
runat="server"/>
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lblPID" Text='<%# Container.DataI tem("PID") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:LinkButt on ID="lnkPName" CommandArgument ="PName" Text="PRODUCT"
runat="server"/>&nbsp;<img id="imgPName" src="Up.gif" visible="false"
runat="server"/>
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lblPName" Text='<%# Container.DataI tem("PName") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<%-- a few more TemplateColumns as shown above come here --%>

<asp:BoundColum n DataField="Qty" HeaderText="QTY " SortExpression= "Qty"/
>
<asp:EditComman dColumn CancelText="CAN CEL" EditText="EDIT"
HeaderText="EDI T" UpdateText="UPD ATE"/>

</asp:DataGrid>

The problem is when the DataGrid is sorted by the QTY column
irrespective of whether the DataGrid is in the editable mode or not, I
can't seem to find a way to render the image along with the HeaderText
*QTY* since it's a BoundColumn.

Is there any way by which I can make the HeaderText display the image
when the DataGrid is sorted by the QTY column?

Replacing the BoundColumn with a TemplateColumn, adding a TextBox in
the ItemTemplate of the TemplateColumn & making it visible/invisible
as & when the EDIT button is clicked could be one option but that I
guess would entail a lot of additional code to make the TextBox
corresponding to the row in which the EDIT button is clicked visible.

Mar 16 '07 #1
1 3314
Hi,
Please find below some that i use in situations like your's, the code
changes the header to add an image that represent the current sort order

#Region "Data Grid Sorting"
Private Sub grdResult_SortC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridSortCommand EventArgs) Handles
grdResult.SortC ommand

If ViewState(e.Sor tExpression + "SortDirection" ) Is Nothing Then
ViewState(e.Sor tExpression + "SortDirection" ) = "ASC"
End If
ChangeHeaderIma ge(e.SortExpres sion, ViewState(e.Sor tExpression +
"SortDirection" ).ToString())
BindGrid(e.Sort Expression + " " + ViewState(e.Sor tExpression +
"SortDirection" ))
SwapSortDirecti on(e.SortExpres sion + "SortDirection" )

End Sub
Sub ChangeHeaderIma ge(ByVal sortBy As String, ByVal dir As String)

Dim im As String
If dir = "ASC" Then
im = " <img border=0 src=""../images/up.gif"" "
Else
im = " <img border=0 src=""../images/dn.gif"" "
End If
Dim col As DataGridColumn
For Each col In grdResult.Colum ns
If col.SortExpress ion = sortBy Then
Dim text As String = col.HeaderText
Dim pos As Integer = col.HeaderText. IndexOf(" ")
If pos -1 Then
text = col.HeaderText. Substring(0, pos)
End If
col.HeaderText = String.Concat(t ext, im)
Else
Dim text As String = col.HeaderText
Dim pos As Integer = col.HeaderText. IndexOf(" ")
If (pos -1) Then
col.HeaderText = col.HeaderText. Substring(0, pos)
End If
End If
Next
End Sub

Sub ClearHeaderImag es()

Dim col As DataGridColumn
For Each col In grdResult.Colum ns
Dim text As String = col.HeaderText
Dim pos As Integer = col.HeaderText. IndexOf(" ")
If (pos -1) Then
col.HeaderText = col.HeaderText. Substring(0, pos)
End If
Next
End Sub
Sub SwapSortDirecti on(ByVal viewStateKey As String)
If ViewState(viewS tateKey).ToStri ng() = "ASC" Then
ViewState(viewS tateKey) = "DESC"
Else
ViewState(viewS tateKey) = "ASC"
End If
End Sub
#End Region
"rn**@rediffmai l.com" wrote:
A DataGrid has a BoundColumn which changes to a TextBox when the
DataGrid is in the editable mode. The rest of the columns in the
DataGrid are TemplateColumns . There's an EditCommandColu mn as well.
All the columns including the BoundColumn but excluding the
EditCommandColu mn can be sorted. The column sorted is also accompanied
by an image to indicate whether a column has been sorted ascendingly
or descendingly. The image gets rendered when the ItemDataBound event
of the DataGrid fires. This is the DataGrid:

<asp:DataGrid ID="dgCart"
OnEditCommand=" EditCart"...OnI temDataBound="B indCart" runat="server">

<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:LinkButt on ID="lnkPID" CommandArgument ="PID" Text="ID"
runat="server"/<img id="imgPID" src="Up.gif" visible="false"
runat="server"/>
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lblPID" Text='<%# Container.DataI tem("PID") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:LinkButt on ID="lnkPName" CommandArgument ="PName" Text="PRODUCT"
runat="server"/<img id="imgPName" src="Up.gif" visible="false"
runat="server"/>
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lblPName" Text='<%# Container.DataI tem("PName") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<%-- a few more TemplateColumns as shown above come here --%>

<asp:BoundColum n DataField="Qty" HeaderText="QTY " SortExpression= "Qty"/

<asp:EditComman dColumn CancelText="CAN CEL" EditText="EDIT"
HeaderText="EDI T" UpdateText="UPD ATE"/>

</asp:DataGrid>

The problem is when the DataGrid is sorted by the QTY column
irrespective of whether the DataGrid is in the editable mode or not, I
can't seem to find a way to render the image along with the HeaderText
*QTY* since it's a BoundColumn.

Is there any way by which I can make the HeaderText display the image
when the DataGrid is sorted by the QTY column?

Replacing the BoundColumn with a TemplateColumn, adding a TextBox in
the ItemTemplate of the TemplateColumn & making it visible/invisible
as & when the EDIT button is clicked could be one option but that I
guess would entail a lot of additional code to make the TextBox
corresponding to the row in which the EDIT button is clicked visible.

Mar 17 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3105
by: Ronny Sigo | last post by:
Hello all, On my form I have an unbound combobox with with 3 columns. It gets its values from a query. On the property sheet of the combobox its BoundColumn property is set to 2 At runtime I want to change the BoundColumn property : Dim sOndertekenaar1 As String, sFunctieOndertekenaar1 As String Me!cbxOndertekenaar1.BoundColumn = 1 sOndertekenaar1 = Nz(Trim(Me!cbxOndertekenaar1.Value)) Me!cbxOndertekenaar1.BoundColumn = 3
3
2350
by: John | last post by:
The ItemCommand event not getting fired when I add both a BoundColumn and a ButtonColumn to a datagrid. When I add a ButtonColumn by itself, everything works fine, but as soon as I add a BoundColumn, the ItemCommand event doesn't seem to get called. I've been struggling with this for too long now, I'm certain there's something I'm not getting. Here's the relevant code. Thanks in advance! // As is, this code does not correctly call...
3
303
by: tshad | last post by:
I want to set the size of a BoundColumn, but can't seem to find a property for that. Is there way to say I want the column to be 80px or 20%? Thanks, Tom.
0
1077
by: cntams | last post by:
Hi all, I have a Web Form and using BoundColumn to bind data to the datagrid. I have 2 fields that needs to be formatted. The first one is a DateTime field and the second one is the currency field. The following is part of my code, the following shows a new boundColumn is being created, and the DataFormatString is being specified. Now, I need to format the currency in a multilanguage manner. Can someone tell me how to do so in both...
1
1884
by: niki | last post by:
Hello. I have a problem with custom columns inside the datagrid. I've set up a datagrid that populates from a database; I can edit the datagrid values and update the db, so that's ok. (btw, it's not as easy as the book claims...) Now I'd like to format some columns, say date values, and what's more, I'd like to make some columns not visible and some read-only. I thought BoundColumn could be the solution, but as I create columns this...
2
2147
by: tshad | last post by:
Is there a way to call a function from a boundcolumn tag? I have some icons that I set as visible or not depending on values set in my table. I have a Datagrid that I am binding to and after binding I then go through the DataGrid item by item checking the values and setting the icons accordingly. If I could set them via a function during binding would be better.
3
2918
by: tshad | last post by:
In a datagrid, is there a way to put a tooltip and use a field from the data that is returned from the sql statement to fill it? For example: <asp:BoundColumn DataField="CompanyDesc" HeaderText="Company:" ReadOnly="true" Visible="true" ItemStyle-Width="135px"
4
2675
by: Randall Parker | last post by:
Using ASP.Net v1.1 with C#. I have an asp:DataGrid where one column is specified as follows: <asp:BoundColumn HeaderText="Serial" DataField="owner_serial_num"></asp:BoundColumn> I might get a serial number of X01 or X02 for example. What I want to do is make that serial number be a link to a different page like, say, http://currentURLpath/DetailViewer.aspx&serial="X02"
0
1454
by: mesut | last post by:
Hi colleagues, I'm confused when to use Boundcolumn and when to use TemplateField in ASPX pages. If I use BoundField control how can I get the field value in code behind? If I use BoundField I can't get the value in codebehind if I switch to Template field I can get the value in code with following statment but my sorting is disspeared?
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.