I have the following gridview column:
<dx:GridViewDataCheckColumn FieldName="IsSelect" Caption="#" VisibleIndex="1">
<DataItemTemplate>
<dx:ASPxCheckBox ID="chk1" runat="server">
</dx:ASPxCheckBox>
</DataItemTemplate>
</dx:GridViewDataCheckColumn>
And my server side code is:
ASPxCheckBox chkColorFastness = grdColorFastness.FindRowCellTemplateControl(i, grdColorFastness.Columns["IsSelect"] as GridViewDataColumn, "chk1") as ASPxCheckBox;
I want to find out the checkbox is checked or not.
According to your implementation, You must get checkbox object from the 'DataItemTemplate'. If you are having problem then follow the below reference links:
Find checkbox control in ASPxGridView
Find controls in the DataItem template of ASPxGridView column
After getting the checkbox object you can use the Checked or CheckState property to know that whether it is checked or not. Go through the specified documentation links there you will find more information about these properties and online demo too.
if(chkColorFastness != null)
bool isChecked = chkColorFastness.Checked;
Hope this help..
Related
Googled variations of the title and everything was related to a null value.
I have an issue where the return value from Page.Request.Params["__EVENTTARGET"] duplicates the unique id of the control.
ctl00$MainContent$ActivityTabset$TabNewActivity$cbxActivityCode$ctl00$MainContent$ActivityTabset$TabNewActivity$cbxActivityCode
cbxActivityCode.UniqueID returns
ctl00$MainContent$ActivityTabset$TabNewActivity$cbxActivityCode
The following is the code that fails in the comparison. It is in the Page_Load event, and is the only code to execute right now if it is a postback.
string controlName = Page.Request.Params["__EVENTTARGET"];
if (cbxActivityCode.UniqueID == controlName)
{
ConfigureActivityUnits();
}
Here is the definition of the control
<obout:ComboBox ID="cbxActivityCode" runat="server"
DataSourceID="ObjectDataSourceDAOActivity"
FilterType="StartsWith" EmptyText="Select..."
AutoPostBack="true"
OnSelectedIndexChanged="cbxActivityCode_SelectedIndexChanged"
AllowCustomText="false" AutoValidate="true" DataValueField="Id"
DataTextField="Description" EnableViewState="true"
OpenOnFocus="true" MenuWidth="425" AllowEdit="False"
Width="300px">
</obout:ComboBox>
I am new to ASP.net and am wondering if it is possible one of the control attributes is causing this behavior?
Is it possibly a bug with the control?
Are there hooks in ASP.net where someone can manipulate a value which will effect Page.Request.Params["__EVENTTARGET"]? (This is a big messy legacy system, and I have no prior developers as a resource.)
If not any of the above, anyone have any ideas as to what could be causing this?
I am having a formView in which I have EditItemTemplate.
The FormView will be refering to one datasource(say datasource1) and all the values for the controls in edititemtemplate are Populated from that datasource. Till here it is fine.
I have a label in the same formview, edititemtemplate where it should refer to another datasource(say datasource2). (I want the value to be populated from datasource2). How could I do this?
I am a beginner. Please anyone help!!
Any help is appreaciated!!
What I have done is simply bind that element (label in your case, textbox in mine) to another (in my case) sqlDataSource. So the control would get the data from the sdstbInfo, then when I want to write data back, I use the UpdateParameters of the sqlSomething and do it in the code behind.
in the aspx code say "Title" is from a sql datasource called sdsTbInfo
<EditItemTemplate>
<asp:TextBox id="someUNIQUEid" runat="server" Text='<%# Bind("Title") %>' />
.
.
Then when you want to get the new data from that same control and pass it to a different datasource....
private void onButtonClick()
{
//first find the control you want
TextBox tb = fvForm.FindControl["txtBoxWithNewInfo"];
//then pass it's value to the sql datasources update command
sdsSomething.UpdateParameter("thing").DefaultValue = tb.Text.ToString();
.
.
.
sds.Update();
}
Hope this helps
I need to search both the columns in my dropdown eg:Code & Description, if I enter text it will search in both of my columns.How to do this in ASPx ComboBox?
I have given TextFormatString="{0},{1}" Search is working but returns Null in SelectedItem.Value. How to Solve this?
My Code:
<dxe:ASPxComboBox ID="cmbCurrencyGuarDetails" SkinID="ComboBoxList"
runat="server" Width="100%"
ClientInstanceName="cmbCurrencyGuarDetails"
DropDownStyle="DropDownList"
ValueType="System.String"
TextFormatString="{0},{1}"
EnableCallbackMode="true"
IncrementalFilteringMode="Contains"
CallbackPageSize="100">
Thanks in Advance.
You should set ValueField. On client side you can get value directly using cmbCurrencyGuarDetails.GetValue().
You can take selected value with;
cmbCurrencyGuarDetails.Value
and if u didnt add ValueField at server side u must add
<dxe:ASPxComboBox ValueField="ID" ... >
As i suspected about your markup you have set the ValueField Property
If the EnableIncrementalFiltering property is enabled, the value typed
by the end-user into the edit box is searched within the editor's
list, based upon the TextFormatString property's defined format.
If the editor's ASPxComboBox.ValueField property is not defined, the
text value formatted using the TextFormatString property is used
as the editor's value.
e.g.
<dxe:ASPxComboBox ID="cmbCurrencyGuarDetails" SkinID="ComboBoxList"
runat="server" Width="100%"
ClientInstanceName="cmbCurrencyGuarDetails"
DropDownStyle="DropDownList"
ValueType="System.String"
TextFormatString="{0},{1}"
EnableCallbackMode="true"
IncrementalFilteringMode="Contains"
ValueField="CustomerID" /// If object data source then mention property here
CallbackPageSize="100">
References:
DevExpress ASPxComboBox not filtering
As a workaround for the fact that asp:Checkboxes don't have values, I am attempting to dynamically create the ID's of checkboxes in a DataList so that it inserts the primary keys into the control ID. This is surprisingly difficult.
I have placed a PlaceHolder in my DataList ItemTemplate, then in the ItemCreated I create the checkboxes using string.Format("Checkbox{0}", DataBinder(e.Item.DataItem, "ID")). The problem is that this only works in a non-postback condition, as on postback the DataItem is null. And of course ItemDataBound isn't called on PostBack so that won't work either.
I can't seem to find a good way to handle this short of if (IsPostback) dataList.Bind(), which i don't think is a good way to do it.
Can anyone provide me with any alternatives here?
EDIT:
Some additional information. I just realized that part of the problem was because I actually have a DataList within a DataList. The reason DataItem is null is because there is no databinding on postback, and the child data is not saved to viewstate.
Basically, what i'm doing is This, although it's using a DataList rather than Repeater. So, on postback, the Children collection doesn't get set because ItemDataBound isn't called on postback.
EDIT2: To clarify, the problem is largely because of the nested datalists. I have to set the datasource of the nested datalist to a collection field of the first datalist's individual rows fields. On postback, there is no databinding, so it doesn't work.
You could use a similar technique to the one I wrote up in this answer - add a regular CheckBox, and a HiddenField control in the ItemTemplate, and bind the HiddenField to the primary key value e.g.
<ItemTemplate>
<tr>
<td>
<asp:CheckBox runat="server" ID="MyCheckBox" AutoPostBack="true" oncheckedchanged="MyCheckBox_CheckedChanged" />
<asp:HiddenField runat="server" id="DatabaseKeyHiddenField" Value='<%# Eval("DatabaseKey") %>' />
</td>
</tr>
</ItemTemplate>
protected void MyCheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox selectedCheckBox;
DataListItem selectedDataListItem;
HiddenField databaseKeyHiddenField;
string databaseKey;
// Cast the sender object to a CheckBox
selectedCheckBox = (CheckBox)sender;
// Walk up the tree one level so we get the container for both controls
selectedDataListItem = (DataListItem)selectedCheckBox.Parent;
// Get the HiddenField control ...
databaseKeyHiddenField = (HiddenField)selectedDataListItem.FindControl("DatabaseKeyHiddenField");
// ... and read the value
databaseKey = databaseKeyHiddenField.Value;
// Go off and do a database update based on the key we now have
...
}
It's a bit of a workaround rather than exactly what you want to do, but it works!
For my ASP.NET page, in the code behind I load various items/options into a DropDownList but I do not set a default by assigning SelectedIndex. I notice for the postback SelectedIndex is set to 0, even if I never set focus to or changed the value in the DropDownList.
If not otherwise specified in the code behind or markup, will a default value of 0 be used for the SelectedIndex in a postback with a DropDownList? If yes, is this part of the HTML standard for selection lists, or is this just the way it is implemented for ASP.NET?
This is normal behavior for the HTML SELECT control.
Unless the selected property is used, it will always start at the first item (index of 0).
In many cases, I don't want this in ASP.NET because I specifically want the user to select an option.
So what I do is add a blank item which I can then validate.
i.e.
<asp:DropDownList runat="server" DataSourceID="SomeDS" AppendDataBoundItems="true"> // Notice the last property
<asp:ListItem Text="Please select an option" Value="" />
</asp:DropDownList>
This way, I can set a validator which checks if the value is blank, forcing the user to make a selection.
For anybody looking for a way to do this from the code behind, you can add the extra list item there by using the Insert function and specifying an Index of 0, as mentioned in this SO Question. Just make sure to do so after you've called DataBind()
myDropDownList.DataSource = DataAccess.GetDropDownItems(); // Psuedo Code
myDropDownList.DataTextField = "Value";
myDropDownList.DataValueField = "Id";
myDropDownList.DataBind();
myDropDownList.Items.Insert(0, new ListItem("Please select", ""));