|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
iterate through only one column of a datagridI need to access the information in only one column of a datagrid. The
column is column[3]. When iterating through the grid I want to find all instances where the entry is "" and change it to read "N". If the entry !+ "" then I want the entry to read "Y". Any ideas on how I can accomplish this task? Thanks, Dave Hi Dave,
I think it would be far easier to use a template column and work with its data. Just jam in a good ol' IIF() and output the N or Y as the text value depending on the evaluation. I've pasted in some demo code below. Let us know if this helps? Ken Microsoft MVP [ASP.NET] Toronto <form id="Form1" method="post" runat="server"> <asp:datagrid id="DataGrid1" runat="server" autogeneratecolumns="False"> <columns> <asp:templatecolumn> <itemtemplate> <asp:Label runat="server" Text='<%# iif(DataBinder.Eval(Container, "DataItem.AString")="","N","Y") %>'> </asp:label> </itemtemplate> </asp:templatecolumn> </columns> </asp:datagrid> </form> Private Sub Page_Load _ (ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then DataGrid1.DataSource = CreateDataSource() DataGrid1.DataBind() End If End Sub Function CreateDataSource() As DataTable Dim dt As New DataTable Dim dr As DataRow dt.Columns.Add(New DataColumn _ ("IntegerValue", GetType(Int32))) dt.Columns.Add(New DataColumn _ ("StringValue", GetType(String))) dt.Columns.Add(New DataColumn _ ("CurrencyValue", GetType(Double))) dt.Columns.Add(New DataColumn _ ("AString", GetType(String))) Dim i As Integer For i = 0 To 8 dr = dt.NewRow() dr(0) = i dr(1) = "Item " + i.ToString() dr(2) = 1.23 * (i + 1) If (i Mod 2) = 0 Then dr(3) = "" Else dr(3) = "Yup" End If dt.Rows.Add(dr) Next i Return dt End Function 'CreateDataSource Show quoteHide quote "Dave Bailey via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message news:a93a7a74d18b485ba6c9c0819c1dcb0d@DotNetMonster.com... >I need to access the information in only one column of a datagrid. The > column is column[3]. When iterating through the grid I want to find all > instances where the entry is "" and change it to read "N". If the entry > !+ > "" then I want the entry to read "Y". Any ideas on how I can accomplish > this task? > > Thanks, > > Dave > > -- > Message posted via http://www.dotnetmonster.com Thanks,
I'll give this a try. Is it not possible to iterate through a bound column? Why would you want to do that when you can make the change as the row is
being built? Show quoteHide quote "Dave Bailey via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message news:7e87ed8aac4a440497f1210157f74d2f@DotNetMonster.com... > Thanks, > > I'll give this a try. Is it not possible to iterate through a bound > column? > Hi Dave,
Apparently you are a C# guy. You can use what Ken suggested, template column and condition ? truePart : flasePart which is similar to VB IIF(condition, truePart, falsePart) method. That is simple and only code in HTML. Or if you still want to use bound column, then you need process data in ItemDataBound event: e.Item.Cells[3].Text = e.Item.Cells[3].Text.Equals ("") ? "N" : "Y"; HTH Elton Wang elton_w***@hotmail.com >-----Original Message----- through a bound column?>Thanks, > >I'll give this a try. Is it not possible to iterate Show quoteHide quote
Datagrid postback problem?!?
Datagrid window.open Export to PDF Annoyingly simple problem _EditCommand not firing... customising PagerStyle dynamically create datagrid and set its datasource in VB.NET Group Headers in Datagrid Using an IF statment within an ItemTemplate Check Parent-child relationship in datagrid |
|||||||||||||||||||||||