If a checkbox produces TRUE or FALSE, how do I convert to 1 or 0 to save the value to the database?
ASP.NET
<asp:CheckBox ID="cbTermsandcond" runat="server" />
C#
BTermsandcondParam = new SqlParameter();
BTermsandcondParam.ParameterName = "#BTermsandcondParam";
BTermsandcondParam.SqlDbType = SqlDbType.Bit;
BTermsandcondParam.Direction = ParameterDirection.Input;
BTermsandcondParam.Value = cbTermsandcond. ??? ;
EDIT:
I wrote this which worked. But is there a simplier way?
if (cbTermsandcond.Checked == true)
{
BTermsandcondParam.Value = 1;
}
else
{
BTermsandcondParam.Value = 0;
}
Regards
Tea
BTermsandcondParam.Value = cbTermsandcond.Checked
Related
I have an aspx(devexpress) grid. Using which I generate columns dynamically from code behind.Below is the code from my grid_databinding event.
GridViewDataTextColumn bfield = new GridViewDataTextColumn();
if (TestString.YearSelectedNames.ToString().Length > 4)
{ string colName = string.Empty;
if (iCount % 2 == 0)
{
colName = TestString.YearSelectedNames.ToString().Substring(5, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString();
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
else
{
colName = TestString.YearSelectedNames.ToString().Substring(0, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString().Replace('1', ' ');
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
}
else
{
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
}
bfield.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
bfield.HeaderStyle.Wrap = DevExpress.Utils.DefaultBoolean.True;
bfield.Name = dtFreezing.Columns[iCount].ColumnName.Trim();
bfield.Width = Unit.Pixel(120);
bfield.VisibleIndex = iCount;
bfield.DataItemTemplate = new DevxGridViewTemplate(ListItemType.Item, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
bfield.CellStyle.HorizontalAlign = HorizontalAlign.Right;
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
gridViewProductCrop.Columns.Add(bfield);
Here the line of code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
is where I am trying to set the property of the grids' column to display only two decimals after the decimal point.
This line of code doesn't seem to work in the first place.
I have even tried using "{0:0.00}" and "{0:N2}" but in vain
Possible reason being that I am writing this line of code in the grid's databinding event. But how else can I set the column properties from code behind
Try to change this code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
to
this.PropertiesTextEdit.DisplayFormatString = "N2";
i think this happen coz u loop the object(make a new object) and the properties would be overwrite.
CMIIW
I'm having one grid and one link button on that grid which have rowcommand but whenever i click on that button it shows me error that there is no row at column 0.
i've debugged whole code so many time but always it's showing me that there is no column even if there is data in that specific column of dataset.
I'm new to asp.net as well as to sql so only knowing that how to put code but logic is not getting cleared please can anyone clear this query. your help is too much for me.
protected void grdManageBRProperty_RowCommand(object sender, GridViewCommandEventArgs e)
{
Session["prptIdBRP"] = e.CommandArgument.ToString();
string id = Session["prptIdBRP"].ToString();
ds = obj.sel("select tblPropertyMaster.PropertyId, tblPropertyTypeMaster.PropertyTypeName, tblSubPropertyTypeMaster.PropertySubTypeName, tblPropertyMaster.Floor, tblPropertyMaster.PlotArea, tblPropertyMaster.BuitUpArea, tblPropertyMaster.ExpectedAmount, tblCityMaster.CityName, tblLocationMaster.LocationName, tblBuilderMaster.BuilderName, tblPropertyMaster.Description, tblPropertyMaster.Remarks, tblPropertyMaster.Furniture AS Furntr, tblPropertyMaster.IsAdvertise, tblPropertyMaster.Status, tblPropertyMaster.OwnerName, tblPropertyMaster.Address, tblPropertyMaster.ContactNo, tblPropertyMaster.MobileNo, tblPropertyMaster.EmailId from tblPropertyMaster INNER JOIN tblPropertyTypeMaster ON tblPropertyMaster.PropertyTypeId=tblPropertyTypeMaster.PropertyTypeId INNER JOIN tblSubPropertyTypeMaster ON tblPropertyMaster.PropertySubTypeId=tblSubPropertyTypeMaster.PropertySubTypeId INNER JOIN tblCityMaster ON tblPropertyMaster.CityId=tblCityMaster.CityId INNER JOIN tblLocationMaster ON tblPropertyMaster.LocationId=tblLocationMaster.LocationId INNER JOIN tblBuilderMaster ON tblPropertyMaster.BuilderName=tblBuilderMaster.BuilderId where tblPropertyMaster.PropertyId= '" + id + "'");
string furn = ds.Tables[0].Rows[0]["Furntr"].ToString();
if (furn == "True")
{
rbBRPFetchFurnitureYesC.Checked = true;
}
if (furn == "False")
{
rbBRPFetchFurnitureNoC.Checked = true;
}
string stts = ds.Tables[0].Rows[0]["Status"].ToString();
if (stts == "True")
{
rbBRPFetchStatusSoldC.Checked = true;
}
if (stts == "False")
{
rbBRPFetchStatusNtSoldC.Checked = true;
}
string advrts = ds.Tables[0].Rows[0]["IsAdvertise"].ToString();
if (advrts == "True")
{
rbBRPFetchIsAdYesC.Checked = true;
}
if (advrts == "False")
{
rbBRPFetchIsAdNoC.Checked = true;
}
ddlBRPFetchTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertyTypeName"].ToString();
ddlBRPFetchSbTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertySubTypeName"].ToString();
txtBRPFetchFloorC.Text = ds.Tables[0].Rows[0]["Floor"].ToString();
txtBRPFetchPlotAreaC.Text = ds.Tables[0].Rows[0]["PlotArea"].ToString();
txtBRPFetchBiultUpAreaC.Text = ds.Tables[0].Rows[0]["BuitUpArea"].ToString();
txtBRPFetchAmountC.Text = ds.Tables[0].Rows[0]["ExpectedAmount"].ToString();
ddlBRPFetchCityC.SelectedItem.Text = ds.Tables[0].Rows[0]["CityName"].ToString();
ddlBRPFetchLocationC.SelectedItem.Text = ds.Tables[0].Rows[0]["LocationName"].ToString();
ddlBRPFetchBuilderNameC.SelectedItem.Text = ds.Tables[0].Rows[0]["BuilderName"].ToString();
txtBRPFetchDescC.Text = ds.Tables[0].Rows[0]["Description"].ToString();
txtBRPFetchRemrksC.Text = ds.Tables[0].Rows[0]["Remarks"].ToString();
txtBRPFetchOwnerNameC.Text = ds.Tables[0].Rows[0]["OwnerName"].ToString();
txtBRPFetchAddressC.Text = ds.Tables[0].Rows[0]["Address"].ToString();
txtBRPFetchConNumberC.Text = ds.Tables[0].Rows[0]["ContactNo"].ToString();
txtBRPFetchMobNumberC.Text = ds.Tables[0].Rows[0]["MobileNo"].ToString();
txtBRPFetchEmailC.Text = ds.Tables[0].Rows[0]["EmailId"].ToString();
pnlBRPUpdateBySessionCriteria.Visible = true;
pnlSearchBRPByDate.Visible = false;
pnlBRPManageGrid.Visible = false;
}
As a precautionary step always first check Rows are present and then only extract values from rows.
if(ds.Tables[0].Rows.Count > 0)
{
// Your code
}
I am using the DynamicControlsPlaceholder by Denis Bauer to save the viewstate of dynamic controls after postback.
I used DynamicControlsPlaceholder before in an earlier part of my project and it worked flawlessly.
However, today I have run into difficulty. I have created a page where there are a number of text labels, slider bars and textboxes (defined by how many elements there are on a database) as shown below. The slider bars are JuiceUI slider controls and the text boxes are normal ASP.NET textboxes.
After postback the text labels (literal controls) and pie chart disappear, the textboxes reduce in size (text inside remains) and the sliderbars are reset to the lowest value without the ability to move the slider (the sliders cannot move at all).
I am quite new to ASP.NET and I am completely stumped as to why this is happening. Do you think it is a problem with the dynamic control placeholder, JuiceUI slider or my code (see below)?
{
SqlCeCommand cmdb = new SqlCeCommand();
cmdb.CommandText = "SELECT CriteriaName,CriteriaDesc FROM tblCriteria WHERE (DecisionID = #DID)";
cmdb.Parameters.AddWithValue("#DID", DID.Text.Trim());
cmdb.Connection = sqlConnection1;
reader = cmdb.ExecuteReader();
string[] criterianames = new string[critno];
string[] criteriadescs = new string[critno];
int i = 0;
while (reader.Read())
{
criterianames[i] = reader["CriteriaName"].ToString().Trim();
criteriadescs[i] = reader["CriteriaDesc"].ToString().Trim();
i++;
}
reader.Close();
Cont2.Controls.Add(new LiteralControl("<h3>Thank you for contributing to the following decision.<h4>Decision Goal: " + dgoal + "</h4><br><br><center>"));
Series weights = new Series();
weights.ChartType = SeriesChartType.Pie;
double[] yBar = new double[critno];
string[] xBar = new string[critno];
xBar = criterianames;
for (i = 0; i < critno; i++)
{
yBar[i] = 1;
}
ChartArea ca = new ChartArea();
ca.Position = new ElementPosition(0, 0, 100, 100);
ca.InnerPlotPosition = new ElementPosition(0, 0, 100, 100);
ca.BackColor = System.Drawing.Color.Transparent;
Chart piechart = new Chart();
piechart.RenderType = RenderType.ImageTag;
piechart.ChartAreas.Add(ca);
piechart.BackColor = System.Drawing.Color.Transparent;
piechart.Palette= ChartColorPalette.BrightPastel;
piechart.BorderColor = System.Drawing.Color.Black;
piechart.BorderSkin.PageColor = System.Drawing.Color.Transparent;
piechart.BorderSkin.BackColor = System.Drawing.Color.Transparent;
piechart.Width = 800;
piechart.Series.Add(weights);
piechart.ImageStorageMode = ImageStorageMode.UseImageLocation;
piechart.ImageLocation = "~/TempImages/ChartPic_#SEQ(300,3)";
piechart.Series[0].Points.DataBindXY(xBar, yBar);
piechart.DataBind();
Cont2.Controls.Add(piechart);
Cont2.Controls.Add(new LiteralControl("</center><h3>Please provide a weighting for each criterion.</h3><p>Please provide a weighting for each criterion along with a description of why you made this choice. </p>"));
for (i = 0; i < critno; i++)
{
Cont3.Controls.Add(new LiteralControl("<h3>" + criterianames[i] + "</h3><p><strong>Description: </strong>" + criteriadescs[i] + "</p><center>"));
Juice.Slider weightslider = new Juice.Slider();
weightslider.ID = "w" + i.ToString();
weightslider.Min = 1;
weightslider.Value = 50;
weightslider.Max = 100;
weightslider.AutoPostBack = true;
Cont3.Controls.Add(weightslider);
weightslider.ValueChanged += (o, a) =>
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + weightslider.Value.ToString() + "');", true);
};
TextBox wdesc = new TextBox();
wdesc.ID = "wd" + Convert.ToString(i);
wdesc.Rows = 3;
wdesc.Width = 900;
wdesc.TextMode = TextBoxMode.MultiLine;
Cont3.Controls.Add(wdesc);
Cont3.Controls.Add(new LiteralControl("</center>"));
}
Cont3.Controls.Add(new LiteralControl("<p align='right'>"));
Button continue1 = new Button();
continue1.Text = "Continue";
Cont3.Controls.Add(continue1);
Cont3.Controls.Add(new LiteralControl("</p>"));
// Database Disconnect
sqlConnection1.Close();
}
Many thanks for any help you can provide,
Kind regards,
Richard
You could eliminate or confirm the problem exists with Juice UI by creating a page containing nothing more than a Juice UI slider, one of these dynamic placeholders and a label. That'd be the first stop.
If you do run into problems with Juice UI, you can use it's cousin Brew
hey guys,
i have a gridview which displays 10records per page, now i want to implement shift+click option in my gridview, when user clicks on the first row and press shift key and click on the 5th row, all the rows between 1 and 5(1 and 5 inclusive) should be selected...
can anyone suggest how should i do this in javascript.
I take it back, I found a shift+click multiple select solution for a gridview. All credit goes to mdv over at the asp forums.
var _sPreviousRow = null;
function wsCheckRange(p_oGridView, p_oControl, e) {
var l_sCheckID = p_oControl.id;
var l_aCheckIDParts = l_sCheckID.split(p_oGridView.id);
var l_sCurrentRow = l_aCheckIDParts[1].split('_')[1].substring(3);
var l_oEvent = (window.event) ? event : e;
if (l_oEvent.shiftKey) {
if (_sPreviousRow != null && _sPreviousRow != l_sCurrentRow) {
var l_iFirst = 0, l_iLast = 0;
if (parseInt(_sPreviousRow,10) > parseInt(l_sCurrentRow,10)) {
l_iFirst = parseInt(l_sCurrentRow,10);
l_iLast = parseInt(_sPreviousRow,10);
}
else {
l_iFirst = parseInt(_sPreviousRow,10);
l_iLast = parseInt(l_sCurrentRow,10);
}
for (var i = l_iFirst; i < l_iLast; i++) {
var l_sLastRow = (i <= 9 ? '0' + i : i);
var l_sCtrlNew = l_sCheckID.replace('ctl' + l_sCurrentRow, 'ctl' + l_sLastRow);
var l_oCtrlNew = $get(l_sCtrlNew);
if (l_oCtrlNew) {
l_oCtrlNew.checked = p_oControl.checked;
}
}
}
_sPreviousRow = null;
}
else {
_sPreviousRow = l_sCurrentRow;
}
}
I have an ObjectDataSource with an ID of ObjectDataSource1 on a webpage. I also have a gridview in which I am binding the ObjectDataSource.ID to the GridView.DataSourceID. The problem I get is when text is changed in a textbox, the code calls BrokerageTransactions.GetAllWithDt which returns a DataTable. I want to set this datatable as the DataSource for the GridView, but it is telling me that I can't set the DataSouce and DataSourceId together. How can I fix this? Code is below. Also. Why can't you set a DataSourceID and a DataSource when using an ObjectDataSource?
Thanks,
X
protected void BrokerageChange(Object sender, EventArgs e)
{
BrokerageTransactions brokerageaccountdetails =
new BrokerageTransactions();
DataSet ds = BrokerageAccount.GetBrkID2(new
Guid(Membership.GetUser().ProviderUserKey.ToString()),
ddlBrokerageDetails.SelectedItem.Text.ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
brokerageaccountdetails.BrokerageId =
new Guid(dr["BrkrgId"].ToString());
}
ddlBrokerageDetails.SelectedItem.Value =
brokerageaccountdetails.BrokerageId.ToString();
if (txtTransactionsTo.Text != ""
&& txtTransactionsFrom.Text != "")
ObjectDataSource1.FilterExpression =
"convert(CreateDt,System.DateTime)>Convert('" +
Convert.ToDateTime(txtTransactionsFrom.Text) + "',System.DateTime)
and Convert(CreateDt,System.DateTime)<convert('"
+ Convert.ToDateTime(txtTransactionsTo.Text.ToString()) +
"',System.DateTime)";
else if (txtTransactionsFrom.Text != "")
ObjectDataSource1.FilterExpression =
"convert(CreateDt,System.DateTime)>convert('" +
Convert.ToDateTime(txtTransactionsFrom.Text) +
"',System.DateTime)";
else if (txtTransactionsTo.Text != "")
ObjectDataSource1.FilterExpression =
"convert(CreateDt,System.DateTime)
<convert('"
+ Convert.ToDateTime(txtTransactionsTo.Text.ToString()) +
"',System.DateTime)";
else
ObjectDataSource1.FilterExpression = " ";
grvBrokerage.DataSourceID = ObjectDataSource1.ID;
grvBrokerage.DataBind();
DateTime dtTransFrom = Convert.ToDateTime("1/1/1900");
DateTime dtTransTo = System.DateTime.Today;
//TransactionsTo Box is Empty
if ((txtTransactionsFrom.Text.Length > 2)
&& (txtTransactionsTo.Text.Length < 2))
{
dtTransFrom = Convert.ToDateTime(txtTransactionsFrom.Text);
dtTransTo = System.DateTime.Today;
}
//TransactionsFrom Box is Empty
if ((txtTransactionsFrom.Text.Length < 2)
&& (txtTransactionsTo.Text.Length > 2))
{
dtTransFrom = Convert.ToDateTime("1/1/1900");
dtTransTo = Convert.ToDateTime(txtTransactionsTo.Text);
}
//TransactionsFrom Box and TransactionsTo Box is Not Empty
if ((txtTransactionsFrom.Text.Length > 2)
&& (txtTransactionsTo.Text.Length > 2))
{
dtTransFrom = Convert.ToDateTime(txtTransactionsFrom.Text);
dtTransTo = Convert.ToDateTime(txtTransactionsTo.Text);
}
// Fails Here
grvBrokerage.DataSource =
BrokerageTransactions.GetAllWithDt(brokerageaccountdetails.BrokerageId,
dtTransFrom,
dtTransTo);
grvBrokerage.DataBind(); }
You got 2 options:
Do not use the ObjectDataSource at
all. You just use the DataSource
property and Set It grammatically
every time.
You use the DataSourceID property of the GridView and Add 2 plain asp:Parameters with default value set. On the ObjectDataSource_Selecting Event you set these parameters through e.InputParameters[]
Hope this helps.