using System;
using System.Data;
using System.Web;
/// <summary>
/// 获取 已 paraName 开头的From表单中的值,填充到DataTable中。
/// </summary>
/// <param name="dt">数据表</param>
/// <param name="ParaName">开头字段</param>
/// <returns></returns>
public static void getFromSameRecord(ref DataTable dt, string ParaName)
{
if (dt != null && dt.Rows.Count != 0)
{
try
{
ParaName = ParaName.ToLower();
int count = HttpContext.Current.Request.Form.Keys.Count;
for (int i = 0; i < count; i++)
{
string text = HttpContext.Current.Request.Form.GetKey(i).ToLower();
int num = text.IndexOf(ParaName);
if (num >= 0)
{
string text2 = text.Substring(num, text.Length - num);
if (dt.Columns.Contains(text2))
{
string value = HttpContext.Current.Request.Form[i].ToString().Trim();
if (!string.IsNullOrEmpty(value))
{
dt.Rows[0][text2] = value;
}
else
{
dt.Rows[0][text2] = DBNull.Value;
}
}
}
}
}
catch
{
}
}
}
自动获取form内的name值,然后装载到Datatable
最新推荐文章于 2022-06-08 14:12:52 发布