本文整理汇总了C#中System.Web.UI.WebControls.GridView类的典型用法代码示例。如果您正苦于以下问题:C# GridView类的具体用法?C# GridView怎么用?C# GridView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GridView类属于System.Web.UI.WebControls命名空间,在下文中一共展示了GridView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetSortImageStates
/// <summary>
/// Sets the sort image states.
/// </summary>
/// <param name="gridView">The grid view.</param>
/// <param name="row">The row.</param>
/// <param name="columnStartIndex"> </param>
/// <param name="sortField">The sort field.</param>
/// <param name="sortAscending">if set to <c>true</c> [sort ascending].</param>
public static void SetSortImageStates(GridView gridView, GridViewRow row,int columnStartIndex, string sortField, bool sortAscending)
{
for (var i = columnStartIndex; i < row.Cells.Count; i++)
{
var tc = row.Cells[i];
if (!tc.HasControls()) continue;
// search for the header link
var lnk = tc.Controls[0] as LinkButton;
if (lnk == null) continue;
// initialize a new image
var img = new Image
{
ImageUrl = string.Format("~/images/{0}.png", (sortAscending ? "bullet_arrow_up" : "bullet_arrow_down")),
CssClass = "icon"
};
// setting the dynamically URL of the image
// checking if the header link is the user's choice
if (sortField == lnk.CommandArgument)
{
// adding a space and the image to the header link
//tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(img);
}
}
}
示例2: Add
public static long Add(string book, DateTime valueDate, string partyCode, int priceTypeId, GridView grid, string referenceNumber, string statementReference)
{
MixERP.Net.Common.Models.Transactions.StockMasterModel stockMaster = new MixERP.Net.Common.Models.Transactions.StockMasterModel();
Collection<MixERP.Net.Common.Models.Transactions.StockMasterDetailModel> details = new Collection<MixERP.Net.Common.Models.Transactions.StockMasterDetailModel>();
long nonGlStockMasterId = 0;
stockMaster.PartyCode = partyCode;
stockMaster.PriceTypeId = priceTypeId;
if(grid != null)
{
if(grid.Rows.Count > 0)
{
foreach(GridViewRow row in grid.Rows)
{
MixERP.Net.Common.Models.Transactions.StockMasterDetailModel detail = new MixERP.Net.Common.Models.Transactions.StockMasterDetailModel();
detail.ItemCode = row.Cells[0].Text;
detail.Quantity = MixERP.Net.Common.Conversion.TryCastInteger(row.Cells[2].Text);
detail.UnitName = row.Cells[3].Text;
detail.Price = MixERP.Net.Common.Conversion.TryCastDecimal(row.Cells[4].Text);
detail.Discount = MixERP.Net.Common.Conversion.TryCastDecimal(row.Cells[6].Text);
detail.TaxRate = MixERP.Net.Common.Conversion.TryCastDecimal(row.Cells[8].Text);
detail.Tax = MixERP.Net.Common.Conversion.TryCastDecimal(row.Cells[9].Text);
details.Add(detail);
}
}
}
nonGlStockMasterId = MixERP.Net.DatabaseLayer.Transactions.NonGLStockTransaction.Add(book, valueDate, MixERP.Net.BusinessLayer.Helpers.SessionHelper.OfficeId(), MixERP.Net.BusinessLayer.Helpers.SessionHelper.UserId(), MixERP.Net.BusinessLayer.Helpers.SessionHelper.LogOnId(), referenceNumber, statementReference, stockMaster, details);
return nonGlStockMasterId;
}
示例3: ChecklistRulesInformationEmptyFix
protected void ChecklistRulesInformationEmptyFix(GridView grdChecklistRulesInformation)
{
if (grdChecklistRulesInformation.Rows.Count == 0)
{
DateTime lastService = new DateTime();
DateTime nextDue = new DateTime();
UnitInformationTDS.ChecklistDetailsDataTable dt = new UnitInformationTDS.ChecklistDetailsDataTable();
dt.AddChecklistDetailsRow(0, "", "", lastService, nextDue, false, "Unknown", false);
Session["unitsChecklistRulesEditDummy"] = dt;
grdChecklistRulesInformation.DataBind();
}
// normally executes at all postbacks
if (grdChecklistRulesInformation.Rows.Count == 1)
{
UnitInformationTDS.ChecklistDetailsDataTable dt = (UnitInformationTDS.ChecklistDetailsDataTable)Session["unitsChecklistRulesEditDummy"];
if (dt != null)
{
// hide row
grdChecklistRulesInformation.Rows[0].Visible = false;
grdChecklistRulesInformation.Rows[0].Controls.Clear();
}
}
}
示例4: HandleService
/// <summary>
/// Sorts the records in the specified <see cref="GridView"/>.
/// </summary>
/// <param name="action">The 'Sorting' <see cref="GridAction"/> to perform.</param>
/// <param name="view">The <see cref="GridView"/> to sort.</param>
/// <param name="p">The parameters used for sorting.</param>
public void HandleService(GridAction action, GridView view, params object[] p)
{
if (view == null) return;
if (!view.AllowSorting) return;
if (action != GridAction.Sorting) return;
// Handle sorting
GridViewSortEventArgs args = p[0] as GridViewSortEventArgs;
if (args == null) return;
if (args.SortExpression == LastExpression)
{
SortAscending = !SortAscending;
}
else
{
SortAscending = true;
LastExpression = args.SortExpression;
}
args.SortDirection = SortDirection;
if (view.DataSource is IDomainCollection)
{
IDomainCollection col = (IDomainCollection)view.DataSource;
col.Sort(args.SortExpression, (args.SortDirection == SortDirection.Ascending) ? SortOrder.Ascending : SortOrder.Descending);
view.DataSource = col;
}
view.DataBind();
}
示例5: Show
internal static void Show(GridView ListTests, string UserName)
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
string str = "select d.Discipline_name, c.categories_name, t.name, ct.points, ct.dateComplite " +
" from Complite_test as ct inner join test as t on ct.test_id = t.test_id " +
" inner join Categories as c on c.cat_id = t.cat_id " +
" inner join discipline as d on d.discipline_id = c.discipline_id " +
" inner join users as u on u.user_id = ct.user_id where u.login = @login";
SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.AddWithValue("login", UserName);
try
{
con.Open();
SqlDataSource ds = new SqlDataSource(con.ConnectionString, str);
Parameter p = new Parameter("login", System.Data.DbType.String, UserName);
ds.SelectParameters.Add(p);
ListTests.DataSource = ds;
ListTests.DataBind();
}
catch (Exception)
{
throw new ApplicationException("Не удается отобразить список завершенных тестов");
}
finally {
con.Close();
}
}
示例6: ViewCards
public ActionResult ViewCards(CardInput cardInput)
{
if (ModelState.IsValid)
{
CardGenerator cardGenerator = new CardGenerator(cardInput.GeneratingDate, cardInput.NumberOfCards);
List<Card> CardList = cardGenerator.GetCardsList();
CardDAO cardDAO = new CardDAO();
if (!cardDAO.ISExsistCardDate(CardList[0].CardNumber))
{
GridView gridView = new GridView();
gridView.DataSource = CardList;
gridView.DataBind();
Session["CardsListEXCEL"] = gridView;
Session["CardsList"] = CardList;
return View(CardList);
}
else
{
ModelState.AddModelError("", "You have already generated cards on this date, so choose aonther date. ");
return View("ShowCards");
}
}
else
{
ModelState.AddModelError("", "Card List is not available");
return View("ShowCards");
}
}
示例7: SetSortImageStates
/// <summary>
/// Sets the sort image states.
/// </summary>
/// <param name="gridView">The grid view.</param>
/// <param name="row">The row.</param>
/// <param name="sortField">The sort field.</param>
/// <param name="sortAscending">if set to <c>true</c> [sort ascending].</param>
public static void SetSortImageStates(GridView gridView, GridViewRow row,int columnStartIndex, string sortField, bool sortAscending)
{
for (int i = columnStartIndex; i < row.Cells.Count; i++)
{
TableCell tc = row.Cells[i];
if (tc.HasControls())
{
// search for the header link
LinkButton lnk = (LinkButton)tc.Controls[0];
if (lnk != null)
{
// initialize a new image
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
// setting the dynamically URL of the image
img.ImageUrl = "~/images/" + (sortAscending ? "bullet_arrow_up" : "bullet_arrow_down") + ".png";
img.CssClass = "icon";
// checking if the header link is the user's choice
if (sortField == lnk.CommandArgument)
{
// adding a space and the image to the header link
//tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(img);
}
}
}
}
}
示例8: ExportClientsListToExcel
public void ExportClientsListToExcel()
{
var grid = new System.Web.UI.WebControls.GridView();
string[] ClientsList={"mike","jonh","vladimit"};
grid.DataSource = /*from d in dbContext.diners
where d.user_diners.All(m => m.user_id == userID) && d.active == true */
from d in ClientsList
select new
{
FirstName = d
};
grid.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=Exported_Diners.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
示例9: UpdateAdminRoomGrid
public static void UpdateAdminRoomGrid(GridView gv)
{
if (superRoomList.Count == 0)
{
return;
}
if (gv.Rows.Count != superRoomList.Count)
{
return;
}
for (var i = 0; i < superRoomList.Count; i++)
{
var r = superRoomList[i];
gv.Rows[i].Cells[0].Text = r.Name;
gv.Rows[i].Cells[1].Text = r.MaxParticipants.ToString();
var s = string.Empty;
int j;
for (j = 0; j < r.Inventories.Count() - 1; j++)
{
s += r.Inventories[j].ProductName + ", ";
}
if (r.Inventories.Count() != 0)
{
s += r.Inventories[j].ProductName;
}
gv.Rows[i].Cells[2].Text = s;
}
}
示例10: GroupCol
/// <summary>
/// 合并GridView中某列相同信息的行(单元格)
/// </summary>
/// <param name="GridView1"></param>
/// <param name="cellNum"></param>
public static void GroupCol(GridView gridView, int cols)
{
if (gridView.Rows.Count < 1 || cols > gridView.Rows[0].Cells.Count - 1)
{
return;
}
TableCell oldTc = gridView.Rows[0].Cells[cols];
for (int i = 1; i < gridView.Rows.Count; i++)
{
TableCell tc = gridView.Rows[i].Cells[cols];
if (oldTc.Text == tc.Text)
{
tc.Visible = false;
if (oldTc.RowSpan == 0)
{
oldTc.RowSpan = 1;
}
oldTc.RowSpan++;
oldTc.VerticalAlign = VerticalAlign.Middle;
}
else
{
oldTc = tc;
}
}
}
示例11: btnDownload_Click
protected void btnDownload_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=Baogia.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
DataSet dts = new DataSet();
SqlDataAdapter adt = new SqlDataAdapter();
SqlCommand comm = new SqlCommand("Export_to_Excel", objConn.SqlConn());
comm.CommandType = CommandType.StoredProcedure;
comm.Connection.Open();
adt.SelectCommand = comm;
adt.Fill(dts);
GridView g = new GridView();
g.DataSource = dts;
g.DataBind();
g.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
示例12: BindItemData
private void BindItemData(GridView itemsview, int TopicID)
{
DataTable table = (DataTable) this.ViewState["dtcount"];
DataRow[] rowArray = table.Select("TopicID=" + TopicID);
object obj2 = table.Compute("sum(SubmitNum)", "TopicID=" + TopicID);
int num = 0;
if (obj2.ToString() != "")
{
num = int.Parse(obj2.ToString());
}
ArrayList list = new ArrayList();
for (int i = 0; i < rowArray.Length; i++)
{
string str = rowArray[i]["Name"].ToString();
int num3 = int.Parse(rowArray[i]["SubmitNum"].ToString());
OptionList list2 = new OptionList {
name = str,
count = num3.ToString(),
totalcount = num.ToString()
};
list.Add(list2);
}
itemsview.DataSource = list;
itemsview.DataBind();
}
示例13: OnInit
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Grid = Parent.Parent.Parent.Parent as GridView;
Row = Parent.Parent as GridViewRow;
Grid.DataBound += new EventHandler(Grid_DataBound);
}
示例14: GroupRows
/// <summary>
/// 合并GridView中某列相同信息的行(单元格)
/// </summary>
/// <param name="GridView1">GridView</param>
/// <param name="cellNum">第几列</param>
public static void GroupRows(GridView GridView1, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}
示例15: AddRepairsNewEmptyFix
protected void AddRepairsNewEmptyFix(GridView grdView)
{
if (grdRepairs.Rows.Count == 0)
{
int companyId = Int32.Parse(hdfCompanyId.Value);
PointRepairsTDS.RepairDetailsDataTable dt = new PointRepairsTDS.RepairDetailsDataTable();
dt.AddRepairDetailsRow(-1, "PL-A", "Temp", "", DateTime.Now, "", "", 0, "", "", "", "", DateTime.Now, "", "", DateTime.Now, "", false, false, "", false, companyId, false, "", "", "", DateTime.Now);
Session["pointRepairsRepairsTempDummy"] = dt;
SetFilter("Type='Temp' AND Deleted = 0");
grdRepairs.DataBind();
}
// normally executes at all postbacks
if (grdRepairs.Rows.Count == 1)
{
PointRepairsTDS.RepairDetailsDataTable dt = (PointRepairsTDS.RepairDetailsDataTable)Session["pointRepairsRepairsTempDummy"];
if (dt != null)
{
grdRepairs.Rows[0].Visible = false;
grdRepairs.Rows[0].Controls.Clear();
Session.Remove("pointRepairsRepairsTempDummy");
}
}
}