Im new in asp.net.. i been working on this since yesterday and theres no luck to figure it out.. why the other grid wont appear on the page since i already put a flag on its code behind.
hope someone can help me on this. thanks.
protected void Edit_btn_Click(object sender, EventArgs e)
{
if (FLAG_hiddenfield.Value == "T")
{
BIRPER_EDIT_grid.Visible = true;
BIRPER_grid.Visible = false;
Edit_btn.Text = "View";
BIRPER_grid.DataBind();
BIRPER_EDIT_grid.DataBind();
FLAG_hiddenfield.Value = "F";
}
if (FLAG_hiddenfield.Value == "F")
{
BIRPER_grid.Visible = true;
BIRPER_EDIT_grid.Visible = false;
Edit_btn.Text = "Edit";
BIRPER_grid.DataBind();
BIRPER_EDIT_grid.DataBind();
FLAG_hiddenfield.Value = "T";
}
}
It seems your conditional logic is wrong here, replace the two ifs with if else:
if(FLAG_hiddenfield.Value == "T"){
...
}
else if (FLAG_hiddenfield.Value == "F"){
...
}
Note that if GridView contains no data then it is not shown on webpage.
Related
I want to check my form before inserting to prevent insert duplicate ProductSerial in my data base.
so how can i check the txtProductSerial.text with my database and if it is duplicate I PREVENT INSERTION.
This are my codes
protected void fvwSoldForm_ItemInserting(object sender, FormViewInsertEventArgs e)
{
e.Values["DateX"] = DateTime.Now;
e.Values["IsDeleted"] = false;
e.Values["Confirmed"] = false;
var solded = db.SoldedByResellers.ToList();
solded = solded.Where(p => p.ProductSerial == NumericSerial.Text).ToList();
if (solded.Count > 0)
Alert("Please Change the serial code, This code Used before");
//Here WHAT EVER I DO THE INSERTING GOES ON. I WANT TO STOP INSERTING HERE
}
To cancel the operation, set:
e.Cancel = true;
This will prevent the insert from happening. See the MSDN documentation for an example.
My query is
SELECT
deldate,
transno,
matno,
MAT_NAME,
rawpkgno,
MAX(SWITCH(deldate=? ,ORDCASES )) AS [CURRDATE],
MAX(SWITCH(deldate=? ,ORDCASES )) AS [previous_day],
MAX(SWITCH(deldate=? ,ORDCASES )) AS [Last_date]
FROM
invorder
WHERE
invorder.strno =54009
OR [invorder.deldate] IS NULL
GROUP BY
matno,
MAT_NAME,
rawpkgno,
transno,
deldate
I want to edit this from gridview. As this is view I cannot edit it from gridview. But is their any way through which previous_day, Last_date columns can be constant and I can only make changes to CURRDATE column. Kindly help me.
Hi you have to bind the row_added event on grid and there make the all the cell read only except u want editable.. check the below code..
public Form1()
{
InitializeComponent();
dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
}
void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
foreach (DataGridViewCell item in dataGridView1.Rows[e.RowIndex].Cells)
{
// here i used the 5 because i want to make the 5th index cell as editable.
if (item.ColumnIndex == 5)
{
continue;
}
item.ReadOnly = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = bind_your_data_source_here;
dataGridView1.Refresh();
}
you can find the sample from here..
Download
I want to disable some controls on my asp page from a ControlCollection.
This is my code.
foreach (System.Web.UI.Control c in ControlCollection)
{
if (c.GetType().FullName.Equals("System.Web.UI.WebControls.Table"))
{
TableRow t = (TableRow)c;
t.Enabled = false;
}
else if (c.GetType().FullName.Equals("System.Web.UI.WebControls.TextBox"))
{
TextBox t = (TextBox)c;
t.Enabled = false;
}
.......
......
///Like this I do for all controls
}
I need a better approach at this. I searched on Internet but didn't find any solution.
You can use the .OfType<> extension like this in order to have more elegant code:
collection.OfType<Table>().ToList().ForEach(c => c.Enabled = false);
collection.OfType<TextBox>().ToList().ForEach(c => c.Enabled = false)
Do all controls in your list inherit from System.Web.UI.WebControl? If so, than this code may help. (Didn't test it myself)
Type wc = new System.Web.UI.WebControls.WebControl(HtmlTextWriterTag.A).GetType();
foreach (System.Web.UI.Control c in ControlCollection)
{
if (c.GetType().IsSubclassOf(wc))
{
((System.Web.UI.WebControls.WebControl)c).Enabled = false;
}
}
And even more elegant (thanx to Shadow Wizard )
ControlCollection.OfType<System.Web.UI.WebControls.WebControl>().ToList().ForEach(c => c.Enabled = false);
Try to use is.
if (c is Table)
{
}
else if (c is TextBox)
{
}
Or consider doing a switch statement on the type name.
switch (c.GetType().Name.ToLower())
{
case "table":
break;
case "textbox":
break;
}
I have 2 Silverlight DataGrids one on top of another. I want to synchronize their horizontal scrollbars.
I have tried to put them both in separate scrollviewers and set the horizontal offset of source scrollviewer to horizontal offset of target scrollviewer but that does not work, the below DataGrid scrollviewer disappers.I think that might be because these Datagrid are inside a StackPanel?
I also tried to put these 2 grids in a third grid and apply scrollviewer on that but that does not work either
Does anyone have an idea how to go about this?
Thanks a lot in advance
I did this in SL4, have no idea if it works in SL3, sorry. The docs state that the API is there but I have not tried it.
The trick is to use automation peers. Get the scroll pattern automation peers for both grids. When scrolling happens on one grid, scroll the other one through the automation peer.
To make this more concrete, assuming we have 2 grids, named _dgGrowth and _dgTotals:
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
public partial class MyPageWithGrids : Page {
...
private ScrollBar _sbGrowth, _sbTotals;
private AutomationPeer _peerGrowth, _peerTotals;
private bool _ignoreScrollEvents;
private void OnPageLoaded(object sender, RoutedEventArgs e) {
_sbGrowth = GetHorizontalScrollBar(_dgGrowth);
if (_sbGrowth != null) {
_sbGrowth.Scroll += OnScrollGrowthGrid;
}
_sbTotals = GetHorizontalScrollBar(_dgTotals);
if (_sbTotals != null) {
_sbTotals.Scroll += OnScrollTotalsGrid;
}
_peerGrowth = FrameworkElementAutomationPeer.CreatePeerForElement(_dgGrowth);
_peerTotals = FrameworkElementAutomationPeer.CreatePeerForElement(_dgTotals);
}
private ScrollBar GetHorizontalScrollBar(DataGrid parentGrid) {
return parentGrid.Descendents().OfType<ScrollBar>().FirstOrDefault(sb => sb.Name == "HorizontalScrollbar");
}
private void OnScrollTotalsGrid(object sender, ScrollEventArgs e) {
if (! _ignoreScrollEvents) {
SyncHorizontalScroll(_peerTotals, _peerGrowth);
}
}
private void OnScrollGrowthGrid(object sender, ScrollEventArgs e) {
if (! _ignoreScrollEvents) {
SyncHorizontalScroll(_peerGrowth, _peerTotals);
}
}
private void SyncHorizontalScroll(AutomationPeer source, AutomationPeer copy) {
IScrollProvider sourceProvider = null;
if (source != null) {
sourceProvider = (IScrollProvider) source.GetPattern(PatternInterface.Scroll);
}
IScrollProvider copyProvider = null;
if (copy != null) {
copyProvider = (IScrollProvider) copy.GetPattern(PatternInterface.Scroll);
}
if (sourceProvider != null && copyProvider != null) {
_ignoreScrollEvents = true;
// scroll copy at horizontal position of source, and keep vertical position
copyProvider.SetScrollPercent(sourceProvider.HorizontalScrollPercent, copyProvider.VerticalScrollPercent);
_ignoreScrollEvents = false;
}
}
}
What is not shown is setting up the Loaded event to OnPageLoaded and the Descendants() method found in this question.
I'm trying to add a custom filter to my RadGrid. I have a column, vendNum, which I want to allow users to filter on multiple vendNums with a comma-separated list. Basically, I want the same functionality as an "in" statement in SQL (where vendNum in (X,Y,Z)).
I followed the tutorial on this site and came up with the following code to place in my RadGrid1_ItemCommand event.
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
switch (filterPair.Second.ToString())
{
case "vendNum":
TextBox tbPattern = (e.Item as GridFilteringItem)["vendNum"].Controls[0] as TextBox;
if (tbPattern.Text.Contains(","))
{
string[] values = tbPattern.Text.Split(',');
if (values.Length >= 2)
{
e.Canceled = true;
StringBuilder newFilter = new StringBuilder();
for (int i = 0; i < values.Length; i++)
{
if (i == values.Length - 1)
newFilter.Append("[vendNum] = " + values[i]);
else
newFilter.Append("[vendNum] = " + values[i] + " OR ");
}
if (RadGrid1.MasterTableView.FilterExpression == "")
RadGrid1.MasterTableView.FilterExpression = newFilter.ToString();
else
RadGrid1.MasterTableView.FilterExpression = "((" + RadGrid1.MasterTableView.FilterExpression + ") AND (" + newFilter.ToString() + "))";
RadGrid1.Rebind();
}
}
break;
default:
break;
}
}
}
Doing this, though, keeps giving me an error "Expression Expected" when I try to filter with a comma separated list. I'm still able to filter a single vendNum. My FilterExpression does come out as expected. The code is failing on the RadGrid1.Rebind() statement. Has anyone dealt with this before? Any help is greatly appreciated.
Thanks,
Aaron
Forgot to Edit This
I solved this problem weeks ago...I had to set the "EnableLinqExpressions" property to false under the RadGrid.
I saw this as a fix for this question somewhere.
Try adding:
RadGrid1.EnableLinqExpressions = false;