为什么我得到"0位没有行"异常:
DSGeneral dg = new DSGeneral();
// I create 1 table
DSGeneral.GeneralDataTable t = new DSGeneral.GeneralDataTable();
dg.Tables.Add(t);
// The 1st row
DSGeneral.GeneralRow r = t.NewGeneralRow();
r.Code = "code";
r.Value = "7";
t.Rows.Add(r);
// The 2nd row
DSGeneral.GeneralRow r2 = t.NewGeneralRow();
r2.Code = "exp";
r2.Value = "5";
t.Rows.Add(r2);
Run Code Online (Sandbox Code Playgroud)
它扔在这里:
int numClave = Convert.ToInt16(dg.General[0].Value);
Run Code Online (Sandbox Code Playgroud)
此外,调试我可以看到我的类型数据集dg有2个表,我想知道为什么.
我有几个文本框,我需要在发回之前检查.我使用每个函数使用jQuery执行此操作.按下提交按钮(LinkButton1)时,我遍历文本框并检查它们的值:
<asp:textbox id="txt1" class="tocheck" runat="server />
<asp:textbox id="txt2" class="tocheck" runat="server />
<asp:textbox id="txt3" class="tocheck" runat="server />
$('#LinkButton1').click(function () {
var error = false;
$.each('.tocheck', function (i, v) {
checkVal(v.val());
});
});
Run Code Online (Sandbox Code Playgroud)
但是抛出运行时错误,说v未定义:

如何检索文本框值?
谢谢.
我想绑定一个启用事件change和按钮的函数keypress.有比这更好的方式:
$(':input').change(function () {
onInputChange();
}).keypress(function () {
onInputChange();
});
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个带有几个链接按钮 的菜单<a class="selected">.当我点击一个我应用一个类时selected,当我点击另一个时,我必须删除它的类并将此类分配给新单击的链接按钮.
因此,只有一个元素同时具有某个类名,我想选择它以删除此类.
我知道:
$('.myclass').removeClass('myclass');
我认为效率不高,因为它必须检查DOM的所有元素
获取此元素的更有效方法是什么:<a class="selected">并删除它的类selected?
我从codebehind创建一个html列表,如下所示:
HtmlGenericControl list = new HtmlGenericControl("ul");
for (int i = 0; i < 10; i++)
{
HtmlGenericControl listItem = new HtmlGenericControl("li");
Label textLabel = new Label();
textLabel.Text = "Menu"+i;
listItem.Controls.Add(textLabel);
list.Controls.Add(listItem);
}
Run Code Online (Sandbox Code Playgroud)
但渲染列表有子弹,我想阻止它们.
我想扩展ListView控件:
using System;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Resources;
using System.ComponentModel.Design;
using System.Globalization;
namespace My.WebControls
{
/// <summary>
/// my ListView
/// </summary>
[Designer(typeof(System.Web.UI.Design.WebControls.DataBoundControlDesigner))]
public class MyListView : ListView
{
}
}
Run Code Online (Sandbox Code Playgroud)
但编译器没有看到这种控制.我包括命名空间system.web.ui.webcontrols.我还要检查其他什么吗?我使用框架3.5.
这是我的查询:
string sql = @"INSERT INTO MY_TABLE(DATE)
VALUES (convert(datetime, '{0}')";
sql = string.Format(sql, myDate);
Run Code Online (Sandbox Code Playgroud)
myDate是一个C#DateTime对象,并在以下之前具有此值string.format:

MY_TABLE有一个DATE列作为DateTime类型.
我收到了这个错误:
将varchar数据类型转换为日期时间数据类型会导致超出范围的值.
我需要以如下myDate格式存储值:31/12/2013 23:59:00into MY_TABLE.
我需要调试Windows服务的初始化.我有一个在服务初始化期间调用的方法,但由于它在启动时发生,我没有足够的时间使用Visual Studio附加进程.此外,由于服务未启动,因此VS2010的"附加过程"窗口对话框中没有显示.
所以我需要的是通过在启动之前附加到它来调试服务.可能吗?
赋予此属性:
public class Data
{
[Description("DESCRIPTION"), DefaultValue("")]
public string DESCX1{ get; set; }
}
Data data= new Data();
Run Code Online (Sandbox Code Playgroud)
我使用 DESCX1 是因为我可以更轻松地通过属性名称进行一些类型映射,但我更喜欢使用友好的名称来了解 MVC 视图中使用哪个属性。
如果我键入,data.如何使描述在 Visual Studio 2015 IntelliSense 中可见?
给定这两个对象(我用一个非常不同的对象来阐明):
public class Car
{
public string Brand {get;set;}
public int Speed {get;set;}
}
public class Apple
{
public string Variety {get;set;}
public int Production {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
AutoMapper定义projection允许使用不同名称映射属性的:
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Car, Apple>()
.ForMember(dest => dest.Variety, opt => opt.MapFrom( src => src.Brand))
.ForMember(dest => dest.Production, opt => opt.MapFrom(src => src.Speed))
});
Run Code Online (Sandbox Code Playgroud)
这应该可以,但是:
有什么方法可以按照在类中定义的顺序直接映射属性?
Brand -> Variety
Speed -> Production
Run Code Online (Sandbox Code Playgroud)
我正在使用AutoMapper 4.2.1
c# ×5
.net ×3
asp.net ×3
jquery ×3
javascript ×2
asp.net-mvc ×1
automapper ×1
code-behind ×1
css ×1
dataset ×1
datetime ×1
events ×1
html-lists ×1
mapping ×1
sql-server ×1