在绑定之前我可以更改绑定值吗? [英] Can I change the bound value before getting binded?
本文介绍了在绑定之前我可以更改绑定值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Experts,
我有一个Gridview,其绑定字段如下所示。
Hello Experts,
I have a Gridview with bound fields as below.
<asp:GridView ID="gdvAll" runat="server" AllowPaging="true" PageSize="10" AllowSorting="true" OnRowDataBound="gdvAll_RowDataBound"
Style="vertical-align: middle;" HorizontalAlign="Center" OnPageIndexChanging ="ongdvPageIndex_Clicked"
AutoGenerateColumns="false" OnSelectedIndexChanged="OnSelectedIndexChanged" EnableSortingAndPagingCallbacks="false"
CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr">
<Columns>
<asp:TemplateField HeaderText="SNo">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TITRANO" HeaderText="MFI Tracking no" />
<asp:BoundField DataField="TIDEANO" HeaderText="Dealer Account#" />
<asp:BoundField DataField="TINPCLM" HeaderText="Dealer Contact" />
<asp:BoundField DataField="TISTATS" HeaderText="Status" />
<asp:BoundField DataField="TIBATNO" HeaderText="Batch no" />
<asp:BoundField DataField="TIRACKNO" HeaderText="Rack no" />
<asp:BoundField DataField="TICLMNO" HeaderText="Claim Date" />
<asp:ButtonField Text="Details" HeaderText="Details" CommandName="Select" />
<asp:TemplateField HeaderText="File">
<ItemTemplate>
<asp:LinkButton ID="btndownload" runat="server" Text="Download" CommandArgument='<%# Eval("TILOCA") %>'
CommandName="Download" OnClick="btnDownload_Click" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Error Info">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
现在在将字段绑定到Grid之前,我想检查数据表中的列值,如果它是Col16 =是则绑定错误信息带有文本的列文件需要
这是我的绑定代码
Now before binding the fields to Grid, I want to check a column value from the Datatable, if it is Col16="Yes" then bind "Error Info" column with a Text "File required"
Here is my bind code
Private Sub BindGrid()
If (txtClaim.Text.Length > 0) Then
'Dim ds As DataSet = dbnet.GetClaims(txtClaim.Text.ToString())
Dim arr() As String = txtClaim.Text.ToString().Split("-")
Dim condi As String = arr(2)
Dim ds As DataSet = dbnet.GetData1("DEVSUSH.CLTRAINF", "TITID", condi.ToString().Trim())
gdvAll.DataSource = ds.Tables(0)
gdvAll.DataBind()
Else
'Dim dsAll As DataSet = dbnet.GetAllClaims()
Dim dsAll As DataSet = dbnet.GetData1("DEVSUSH.CLTRAINF", "", "")
gdvAll.DataSource = dsAll.Tables(0)
gdvAll.DataBind()
ViewState("gdvAll") = dsAll.Tables(0)
End If
End Sub
Protected Sub gdvAll_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Try
Dim index As Integer = 0
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim ColValue As String = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "TILOCA"))
Dim lnk As LinkButton = DirectCast(e.Row.FindControl("btndownload"), LinkButton)
If Not ColValue Is String.Empty Then
' if Already file is attached show
e.Row.FindControl("btndownload").Visible = True
Else
e.Row.FindControl("btndownload").Visible = False
End If
End If
Catch ex As Exception
LogError.LogErrorIntoTextFile(ex, "gdvAll_RowDataBound()")
End Try
End Sub
这可能吗?如果是的话,你能告诉我该怎么做?
Is this possible? If yes can you tell me how can I do that?
推荐答案
这样的事情可以解决问题:
Something like this should do the trick:
<asp:TemplateField HeaderText="Error Info">
<ItemTemplate>
<asp:Label runat="server"
Visible='<% String.Equals(Eval("Col16", "{0}"), "Yes", StringComparison.OrdinalIgnoreCase) %>'
Text="File required"
/>
</ItemTemplate>
</asp:TemplateField>
这篇关于在绑定之前我可以更改绑定值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文