Repeater and tr runat=server. How to add class to row? - asp.net-4.0

I need to the attribute class (if it doesn't exist) to table row located in a repeater. There's a question is inside the code.
aspx
<asp:Repeater runat="server">........
<ItemTemplate> .....
<tr runat="server" id="row" >
.....................
codeBehind
void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var row= e.Item.FindControl("row");
//how do I use it? How do I add "class" (if not exists) to "row"?
}
}

That object is an HtmlDataRow:
HtmlTableRow row = e.Item.FindControl("row") as HtmlTableRow;
if (row != null )
{
if (string.isNullOrEmpty(row.Attributes["class"]))
{
row.Attributes["class"] = "myClass";
}
else
{
row.Attributes["class"] = string.Format( "{0} {1}", row.Attributes["class"], "myClass");
}
}

Related

Skipping Tab Index on Non Editable column

How to allow Setting Tabindex within the c1 FlexGrid in such a way that it skips a particular column in the c1 FlexGrid.
Is there something I can too do this
Thanks!
There might be a better way, but here's one approach:
public partial class Form1 : Form
{
private Int32 _colIdxToSkip = 4; //Remember, there's an extra column if "Row Headers" are turned on!
private Keys _lastKeys = Keys.None;
public Form1()
{
InitializeComponent();
flexGrid.KeyActionTab = C1.Win.C1FlexGrid.KeyActionEnum.MoveAcross;
}
private void flexGrid_BeforeRowColChange(Object sender, C1.Win.C1FlexGrid.RangeEventArgs e)
{
if (_lastKeys == Keys.Tab && e.OldRange.r1 == e.NewRange.r1 && e.NewRange.c1 == _colIdxToSkip)
{
if (_colIdxToSkip == flexGrid.Cols.Count - 1)
{
flexGrid.Row = (flexGrid.Row == flexGrid.Rows.Count - 1 ? flexGrid.Rows.Fixed : flexGrid.Row + 1);
flexGrid.Col = flexGrid.Cols.Fixed;
}
else
flexGrid.Col = _colIdxToSkip + 1;
e.Cancel = true;
}
}
private void flexGrid_KeyDown(Object sender, KeyEventArgs e)
{
_lastKeys = e.KeyCode;
}
}

need help for inserting multiple row data into database using asp.net mvc4

I have done a simple applicaion using ASP.NET MVC4.
I am trying to insert multiple row data into the database.What i have done that is working fine for single row.
Single row is inserted but in multiple row i am getting a problem... the data are not pass from client side to server side (catch by a form collection object )in controller and also loop is not properly working.
my view is:
<table style="width:100%" id="tbldata">
<tr>
<th>Document </th>
<th>Sem/Year(ifapplicable)</th>
<th>File</th>
</tr>
#for (int i = 0; i < 7; i++ )
{
<tr class="document">
<td style="width:40%">#Html.DropDownListFor(m => m.selectdocId, ViewBag.selectdocId as IEnumerable<SelectListItem>,"--Select--", new { #id="docid" +i , #class="Doctype"})</td>
<td style="width:10%">#Html.TextBoxFor(m => m.sem, new { #id="sem" +i, #class="semid"})</td>
<td style="width:40%"><input type="file" multiple="" name="file" value="Browse" /></td>
</tr>
}
</table>
My controller is:
public ActionResult display(FormCollection collection, IEnumerable<HttpPostedFileBase>file )
{
for(int i=0; i<7; i++)
{
int semid = Convert.ToInt32(collection["sem" + i]);
int docid = Convert.ToInt32(collection["docid" + i]);
tbldocumentdetail doc = new tbldocumentdetail();
doc.sem = Convert.ToInt32(semid);
doc.selectdocId = Convert.ToInt32(docid);
db.tbldocumentdetails.Add(doc);
db.SaveChanges();
}
foreach (var item in file)
{
if (item == null && item.ContentLength < 0)
{
ModelState.AddModelError("file", "please uploded your file");
}
else
{
var filename = Path.GetFileName(item.FileName);
var path = Path.Combine(Server.MapPath("~/Content/savedoc"), filename);
item.SaveAs(path);
tbldocumentdetail doc = new tbldocumentdetail();
doc.fileName = filename;
string a = "~/Content/savedoc" + filename;
doc.path = a;
db.tbldocumentdetails.Add(doc);
db.SaveChanges();
}
For this , Instead of using form collection you can use IEnumerable as the POST action parameter. You can refer below link
MVC Form not able to post List of objects

Pagination not working in SPGridView in Visual Web Part

Paging is not working when I click on pages. Nothing displays. Here is the code,
Markup on my ascx form,
<div class="mGrid">
<SharePoint:SPGridView
runat="server"
ID="gdSharedReport"
AutoGenerateColumns="false"
CssClass="mGrid"
AllowPaging="true"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt"
EmptyDataText="No Survey found."
OnSorting="gdSharedReport_Sorting"
OnPageIndexChanging="gdSharedReport_PageIndexChanging"
/>
</div>
Code on my ascx.cs,
public DataView dv;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GenerateGrid();
}
}
private DataTable BindData()
{
DataTable table;
table = new DataTable();
table.Columns.Add("SurveySet", typeof(string));
table.Columns.Add("SurveySection", typeof(string));
table.Columns.Add("SurveyQuestion", typeof(string));
table.Columns.Add("Employee", typeof(string));
table.Columns.Add("Supervisor", typeof(string));
table.Columns.Add("EmployeeNumber", typeof(string));
table.Columns.Add("SurveyDate", typeof(string));
DataRow row;
try
{
SPListItemCollection collListItems = list.GetItems(oQuery);
row = table.NewRow();
//Logic here to set rows
table.Rows.Add(row);
}
catch(Exception ex){}
return table;
}
private void GenerateGrid()
{
DataTable dt = BindData();
dv = new DataView(dt);
gdSharedReport.DataSource = dv;
gdSharedReport.AutoGenerateColumns = false;
gdSharedReport.AllowSorting = true;
gdSharedReport.Sorting += new GridViewSortEventHandler(gdSharedReport_Sorting);
//Setting bound fields here
gdSharedReport.PageSize = 10;
gdSharedReport.AllowPaging = true;
gdSharedReport.PageIndexChanging +=
new GridViewPageEventHandler(gdSharedReport_PageIndexChanging);
gdSharedReport.PagerTemplate = null;
if (ViewState["SortDirection"] != null && ViewState["SortExpression"] != null)
{
dv.Sort = ViewState["SortExpression"].ToString()
+ " " + ViewState["SortDirection"].ToString();
}
gdSharedReport.DataBind();
}
public void gdSharedReport_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdSharedReport.PageIndex = e.NewPageIndex;
gdSharedReport.DataBind();
}
public void gdSharedReport_Sorting(object sender, GridViewSortEventArgs e)
{
string lastExpression = "";
if (ViewState["SortExpression"] != null)
lastExpression = ViewState["SortExpression"].ToString();
string lastDirection = "asc";
if (ViewState["SortDirection"] != null)
lastDirection = ViewState["SortDirection"].ToString();
string newDirection = "asc";
if (e.SortExpression == lastExpression)
newDirection = (lastDirection == "asc") ? "desc" : "asc";
ViewState["SortExpression"] = e.SortExpression;
ViewState["SortDirection"] = newDirection;
dv.Sort = e.SortExpression + " " + newDirection;
gdSharedReport.DataBind();
}
Here is how grid loads,
Here is what comes when I click to pages,
If I modify following function ,
public void gdSharedReport_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdSharedReport.PageIndex = e.NewPageIndex;
gdSharedReport.DataBind();
}
To,
public void gdSharedReport_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdSharedReport.PageIndex = e.NewPageIndex;
gdSharedReport.DataSource = BindData();
gdSharedReport.DataBind();
}
Then pagination start working but paging number disappears if I click on paging ,
You need to again specify pagination in page index change event.
public void gdSharedReport_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdSharedReport.PageIndex = e.NewPageIndex;
gdSharedReport.AllowPaging = true;
gdSharedReport.PageIndexChanging += new GridViewPageEventHandler(gdSharedReport_PageIndexChanging);
gdSharedReport.PagerTemplate = null;
gdSharedReport.DataSource = BindData();
gdSharedReport.DataBind();
}

Janus 4 GridEx disable rows

I have have a Janus 4 GridEx control which includes a checkbox column.
I need to be able to disable certain rows (i.e make them non selectable/greyed out) depending the value of a particular column. The data for the grid is loaded from a database.
Any help would be appreciated.
You have to utilize the LoadingRow and SelectionChanged events of the Janus Grid.
This is a sample code: ( Here I'm checking the value of a particular column to be divided by 2)
private void grdEx_LoadingRow(object sender, Janus.Windows.GridEX.RowLoadEventArgs e)
{
if (Convert.ToInt32(e.Row.Cells["ID"].Value) % 2 == 0)
{
e.Row.RowStyle = new GridEXFormatStyle(e.Row.Table.RowFormatStyle);
e.Row.RowStyle.BackColor = Color.Gray;
}
}
private void grdEx_SelectionChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(grdEx.GetValue("ID")) % 2 == 0)
{
if (grdEx.Row >= 0)
{
if (grdEx.Row == grdEx.RowCount - 1)
grdEx.Row = grdEx.Row - 1;
else
grdEx.Row = grdEx.Row + 1;
}
}
}
Depending on the Checkbox column , just see the sample code:
private void grdEX1_FormattingRow(object sender, RowLoadEventArgs e)
{
if (e.Row.RowIndex > -1 && e.Row.RowIndex < grdEX1.RowCount)
{
for (int i = 0; i < grdEX1.RootTable.Columns.Count; i++)
{
if (!Convert.ToBoolean(e.Row.Cells["checkboxCol"].Value))//checked So editable
{
e.Row.Cells[i].FormatStyle = new GridEXFormatStyle() { BackColor = Color.LightGray };
}
else
{
e.Row.Cells[i].FormatStyle = null;
}
}
}
}
To prevent the editing if the row is not checked :
private void grdEX1_EditingCell(object sender, EditingCellEventArgs e)
{
if(!Convert.ToBoolean(grdEX1.GetValue("checkboxCol"))) //not checked
{
e.Cancel = true;
return;
}
}

Error in DataGrid random behavior when scrolling in Silverlight 4.0

I have a datagrid and its rows are colored based on certain condtions..There is a vertical scrollbar for my datagrid.. If the user scrolls the datagrid the index of the colored rows r getting changed.. For eg: if 2 row is colored if the user scrolls down and comes up the index of the colored row is getting messed up...
here is the code....
dggeneralconfiguration.LoadingRow += new EventHandler<DataGridRowEventArgs>(grid1_LoadingRow);
dggeneralconfiguration.UnloadingRow += new EventHandler<DataGridRowEventArgs>(grid1_UnloadingRow);
void grid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid;
if (c.Status == false)
{
if (e.Row != null)
{
e.Row.Background = new SolidColorBrush(Colors.Red);
//e.Row.Background = new SolidColorBrush(Colors.Transparent);
}
}
}
void grid1_UnloadingRow(object sender, DataGridRowEventArgs e)
{
ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid;
if (c.Status == false)
{
if (e.Row != null)
{
e.Row.Background = new SolidColorBrush(Colors.Red);
//e.Row.Background = new SolidColorBrush(Colors.Transparent);
}
}
}
Better late than never. ;-) . I too had similar kind of problem.. try assigning row background to null on unloading row event.
private void dg_UnloadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Background = null;
}