我有以下VB代码:
Dim dt As DataTable = DAL.WMS_Collaboration_Fetch(0).Tables(0)
If dt.Rows.Count > 0 Then
'Bind Dataset to Gridview
Dim _WMS_CollaborationInfo As New WMS_CollaborationInfo
With _WMS_CollaborationInfo
.CollaborationName = dt.Rows(0).Item["CollaborationName").ToString
.CollaborationID = dt.Rows(0).Item("CollaborationID").ToString
End With
Run Code Online (Sandbox Code Playgroud)
将它转换为C#代码,如下所示:
DataTable dt = DAL.WMS_Collaboration_Fetch(0).Tables(0);
if (dt.Rows.Count > 0) {
//Bind Dataset to Gridview
WMS_CollaborationInfo _WMS_CollaborationInfo = new WMS_CollaborationInfo();
{
_WMS_CollaborationInfo.CollaborationName = dt.Rows[0].Item["CollaborationName"].ToString;
_WMS_CollaborationInfo.CollaborationID = dt.Rows[0].Item["CollaborationID"].ToString;
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法运行C#代码.在VB中,使用DataTable的表列只需传入列名即可访问(好吧,我对VB不太了解),例如"CollaborationID"in
dt.Rows(0).Item("CollaborationID").ToString
Run Code Online (Sandbox Code Playgroud)
请问使用DataTable从表中读取数据的C#等价物是什么?我只是说我如何重新编写我的C#代码以便它可以工作.
我有以下GridView:
<asp:GridView ID="gridCar" runat="server" RowStyle-ForeColor="Black" AllowSorting="true" OnSorting="gridCar_Sorting" AutoGenerateEditButton="true" OnRowEditing="gridCar_RowEditing" OnRowCancelingEdit="gridCar_RowCancelingEdit" OnRowUpdating="gridCar_RowUpdating" OnRowUpdated="gridCar_RowUpdated"></asp:GridView>
Run Code Online (Sandbox Code Playgroud)
我想更新编辑按钮选择的行.问题是,如果我尝试进行gridCar_RowUpdating,e.NewValues则不包含已编辑的值,而是包含旧的值.
我四处搜寻,发现我可能不得不使用onRowUpdated事件,但后来又面临另一个问题; 这个事件根本没有被解雇.我试图进入e.Cancel = false,gridCar_RowUpdating但这不会解决问题.
GridView绑定到DataTable.
编辑:这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : Page
{
DataTable carsTable = new DataTable("cars");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
carsTable.Columns.Add("CarID");
carsTable.Columns.Add("CarRegNum");
carsTable.Columns.Add("CarModel");
carsTable.Columns.Add("CarType");
carsTable.Columns.Add("CarOwner");
carsTable.Rows.Add(1, "AAA-111", "Toyota", "Hatchback", "Matti");
carsTable.Rows.Add(2, "BBB-222", "Mercedes-Benz", "Van", "Keijo"); …Run Code Online (Sandbox Code Playgroud) 我面临以下问题:当我尝试绑定Telerik Treeview时
这些列目前没有唯一值.
我的代码:
protected void BindRTV()
{
rtv_acd.DataTextField = "name";
rtv_acd.DataValueField = "main_id";
rtv_acd.DataFieldID = "main_code";
rtv_acd.DataFieldParentID = "father_code";
rtv_acd.DataSource = dt;
rtv_acd.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
数据快照:

如何解决这个问题,我知道这main_code是重复但我想要的.
我有一个类似的问题:Primefaces:confirmDialog中的commandButton无法以相同的形式更新数据表
我有一个游戏桌.在最后一列中有2个按钮:删除和详细信息.
删除按钮应该删除游戏
该按钮确实删除了游戏,但更新不起作用.
update =":form1:overviewTableGame" - >没有反应(没有刷新)
update ="@ form" - >更新performes(表刷新),但整个scren被锁定.我认为由于这个事实,包含对话框的表单已更新...
表格代码:
<h:form id="form1">
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:dataTable id="overviewTableGame" var="game" value="#{gameMB.list}">
<p:column headerText="#{msg.ID}" sortBy="#{game.id}">
<h:outputText value="#{game.id}" />
</p:column>
<p:column headerText="#{msg.NAME}" sortBy="#{game.name}">
<h:outputText value="#{game.name}" />
</p:column>
<p:column headerText="#{msg.DESCRIPTION}"
sortBy="#{game.description}">
<h:outputText value="#{game.description}" />
</p:column>
<p:column headerText="#{msg.ADMIN}" sortBy="#{game.admin.firstname}">
<h:outputText value="#{game.admin.firstname}" />
</p:column>
<p:column headerText="#{msg.ACTION}">
<p:commandButton id="commandButtonDELETE" value="löschen"
onclick="confirmation.show()" type="button"
update=":form1:display">
<f:setPropertyActionListener value="#{game}"
target="#{gameMB.selectedGame}" />
</p:commandButton>
<p:commandButton id="commandButtonDETAIL" value="detail"
action="#{gameMB.details()}">
<f:param name="id" value="#{game.id}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog …Run Code Online (Sandbox Code Playgroud) 我使用了primefaces的复选框数据表,我想禁用数据表的选择样式(更改所选行的颜色),因为我在每行中都有一些链接没有显示
我怎么能实现这一点,
谢谢
我需要对这个DataTable概念有点引导.我将数据存储在DataTable中,我首先添加一个列,如下所示:
DataTable outputData = new DataTable();
outputData.Columns.Add("Reference/Group");
Run Code Online (Sandbox Code Playgroud)
现在,如果我将其写入CSV文件(使用我自己的类),我会得到你所期望的,电子表格软件中的视图如:
A
1 Reference/Group
Run Code Online (Sandbox Code Playgroud)
然而,当我继续在我的脚本中假设存在第1行(通过引用outputData.Rows[0])时,我得到:
Exception: There is no row at position 0.
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试添加具有上述内容的行,则会抱怨没有列.如果我指定列然后添加一行,我可以参考,Rows[0]但到那时我有两行,如:
A
1 Reference/Group
2 Some new row
Run Code Online (Sandbox Code Playgroud)
这里的正确方法是什么,这种行为的原因是什么?
我希望根据某些字段获得不同的记录.我正在使用以下方法:
string[] TobeDistinct = { "PKID" };
DataTable dtDistinct = GetDistinctRecords(ds.Tables[0], TobeDistinct);
DataSet ds2 = new System.Data.DataSet();
ds2.Tables.Add(dtDistinct);
public static DataTable GetDistinctRecords(DataTable dt, string[] Columns)
{
DataTable dtUniqRecords = new DataTable();
dtUniqRecords = dt.DefaultView.ToTable(true, Columns);
return dtUniqRecords;
}
Run Code Online (Sandbox Code Playgroud)
这给了我不同的记录,但只有两个记录.只会有两个不同的PKID.例如,我有PKID 10,12,14,16的多个记录,但结果是PKID 10和12的2行.更多的两行不存在,但应该在那里.我需要做什么?
我按照这篇文章:http://www.codeproject.com/Tips/153008/Select-DISTINCT-records-based-on-specified-fields

我试图以编程方式将行添加到asp:table下面是我迄今为止的努力: -
但是datarow不包含getenumorator,我不知道这意味着什么,任何人都可以帮助我吗?
我知道使用转发器更容易但是对于这个页面我需要一个服务器端表,所以我试图这样做,我也如何以正确的顺序添加列数据以匹配表头?
dtEquipment = new dsData.tblEquipmentDataTable();
taEquipment = new dsDataTableAdapters.tblEquipmentTableAdapter();
taEquipment.FillbyUser(dtEquipment);
foreach (DataRow DRow in dtEquipment)
{
TableRow tRow = new TableRow();
foreach (DataColumn dCol in DRow)
{
TableCell tCell = new TableCell();
tCell.Text = DRow["AssetNo"].ToString();
tRow.Cells.Add(tCell);
}
tblTest.Rows.Add(tRow);
}
Run Code Online (Sandbox Code Playgroud) <h:dataTable value="#{SearchingBeans.list}" var="entry">
<h:column>
<f:facet name="header">
<h:outputLabel>Photo</h:outputLabel>
</f:facet>
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel>Pseudo</h:outputLabel>
</f:facet>
<h:outputLabel value="#{entry.pseudo}"></h:outputLabel>
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel>Description</h:outputLabel>
</f:facet>
<h:outputLabel value="#{entry.description}"></h:outputLabel>
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel>Photo</h:outputLabel>
</f:facet>
<h:outputLabel value="#{entry.photo[0].path}"></h:outputLabel> <-- this a List
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
我有一个实体成员他的一个属性是一个列表照片与获取/设置属性填充我不知道如何获取该值在jsf我只想要每个成员的第一张照片,因为他们有2-3张照片.它可能吗?任何其他解决方案将不胜感激.
我试图通过地图项目的列表进行迭代,即包含HashMap或类似的东西的一个ArrayList,我试图做到这一点在primefaces数据表.这基本上就是我要做的事情:
<body>
<h:form>
<p:dataTable value="#{customerBean.list}" var="map">
<c:forEach items="#{map}" var="entry">
<p:column headerText="#{entry.key}">
#{entry.value}
</p:column>
</c:forEach>
</p:dataTable>
</h:form>
</body>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,customerBean.list是List<Map<String, String>>和条目是一个Map<String, String>.
我想要做的,是营造列的动态量的基础上,在条目数量Map<String, String>使用的标题名称映射条目的键的同时,和值作为输出.c:forEach当我使用硬编码时Map<String, String>,这个东西似乎工作正常,但显然它无法循环通过变量p:dataTable.我假设该程序采取预防措施,以避免必须循环不同大小的地图.那么我怎么能做这项工作呢?如何根据Map中的条目数创建任意数量的列?请注意,我100%肯定每个人Map<String, String>的身材都相同List<Map<String, String>>
编辑:
这是我的豆源.代码工作正常,一切,问题只是循环不愿意通过我的地图:
@ManagedBean
@SessionScoped
public class CustomerBean {
private List<Map<String, String>> list = new ArrayList<Map<String, String>>();
private Mapper mapper = new Mapper();
public CustomerBean() {
list = mapper.all(); //gets data from database
}
public List<Map<String, String>> getList() { …Run Code Online (Sandbox Code Playgroud)