Useful Stuff about Grid-views
1.How to manipulate a Grid-view cell in ASP.NET
foreach(DataGridViewRow row in this.Gvorders.Rows)
{
if (row.HeaderCell.Value == txtorder.Text)
{
for (int i = 0; i < Gvorders.Columns.Count; i++)
{
this.Gvorders.CurrentCell = row.Cells[i];
row.Cells[i].Style.BackColor = Color.Green;
}
}
}
Link: http://www.codeproject.com/Tips/387941/How-to-manipulate-a-GridView-cell-in-ASP-NET
2.Using the j Query Tool-tip Plugin in a Grid-view
<asp:TemplateField HeaderText="Category ID" SortExpression="CategoryID" HeaderStyle-Wrap="false">
<ItemStyle Width="30px" HorizontalAlign="Center" />
<ItemTemplate>
<div class="tag">
<a href="#" class="gridViewToolTip"><%# Eval("CategoryID")%>
</a>
<div id="tooltip" style="display: none;">
<table>
<tr>
<td style="white-space: nowrap;"><b>Category ID:</b> </td>
<td><%# Eval("Categories.Value.CategoryID")%></td>
</tr>
<tr>
<td style="white-space: nowrap;"><b>Category Name:</b> </td>
<td><%# Eval("Categories.Value.CategoryName")%></td>
</tr>
<tr>
<td style="white-space: nowrap;"><b>Description:</b> </td>
<td><%# Eval("Categories.Value.Description")%></td>
</tr>
</table>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
Link: http://www.codeproject.com/Articles/238678/Using-The-JQuery-Tooltip-Plugin-in-a-GridView
3.How to click/select Row in ASP.NET Grid-view or HTML Table
protected void grvGroups_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "setGridValue('" + e.Row.ClientID + "')");
}
}
Link:http://www.codeproject.com/Tips/308334/How-to-click-select-Row-in-ASP-NET-GridView-or-HTM
4.Add some Style to your Grid-view
<asp:GridView ID="lostGridView" runat="server" PageSize="5" CellPadding="4" BackColor="#E98A28"
BorderColor="#DEBA84" GridLines="Both" Width="900px" BorderWidth ="1px" CssClass="pager">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#F9A044" Font-Bold="True" ForeColor="#8C4510" />
<HeaderStyle BackColor="#EB9429" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F9A044" CssClass="hidden" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<style type="text/css">
.pager span
{
text-decoration:underline;
font-weight: bold;
font-size: 10pt;
}
</style>
<asp:GridView ID="lostGridView" runat="server" PageSize="5" CellPadding="4" BackColor="#E98A28"
BorderColor="#DEBA84" GridLines="Both" Width="900px" BorderWidth ="1px" CssClass="pager" />
6. Grid-view all in one
What is a GridView?
GridView Fields
1.BoundColumn
2.HyperLinkColumn
3.TemplateColumn
4.CommandField
5.Different Types of Events
6.PageIndexChanging
7.Paging
8.RowCommand
9.RowCreated
10.RowDeleting
11.RowUpdating
12.RowEditing
13.RowDatabound
14.Sorting
15.Header and Footer of the Grid
16.Export GridView to Word, Excel, and PDF
17.Difference between DataGrid, DataList, and Repeater
Link: http://www.codeproject.com/Articles/36528/GridView-all-in-one
7.Implement Paging in a Grid-view
<asp:GridView ID="resultsGridView" runat="server" PageSize="5" AllowPaging="True"
CellPadding="4" BackColor="#E98A28" BorderColor="#DEBA84" GridLines="Both" Width="900px" BorderWidth ="1px" CssClass="pager"
OnPageIndexChanging="resultsGridView_SelectedIndexChanging">
8.Implement Grid-view Column Header Merging
protected void timeSheetGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
//If row type= header customize header cells
if (e.Row.RowType == DataControlRowType.Header)
CustomizeGridHeader((GridView)sender, e.Row, 2);
}
private void CustomizeGridHeader(GridView timeSheetGrid, GridViewRow gridRow, int headerLevels)
{
for (int item = 1; item <= headerLevels; item++)
{
//creating new header row
GridViewRow gridviewRow = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
IEnumerable<IGrouping<string,>> gridHeaders = null;
//reading existing header
gridHeaders = gridRow.Cells.Cast<tablecell>()
.Select(cell => GetHeaderText(cell.Text, item))
.GroupBy(headerText => headerText);
foreach (var header in gridHeaders)
{
TableHeaderCell cell = new TableHeaderCell();
if (item == 2)
{
cell.Text = header.Key.Substring(header.Key.LastIndexOf(_seperator) + 1);
}
else
{
cell.Text = header.Key.ToString();
if (!cell.Text.Contains("DENTRY"))
{
cell.ColumnSpan = 3;
}
}
gridviewRow.Cells.Add(cell);
}
// Adding new header to the grid
timeSheetGrid.Controls[0].Controls.AddAt(gridRow.RowIndex, gridviewRow);
}
//hiding existing header
gridRow.Visible = false;
}
private string GetHeaderText(string headerText, int headerLevel)
{
if (headerLevel == 2)
{
return headerText;
}
return headerText.Substring(0, headerText.LastIndexOf(_seperator));
}
No comments:
Post a Comment