In my code I have this bind set up to a textbox
<asp:TextBox ID="CompanyTextBox" runat="server" Text='<%# Bind("Company") %>' CssClass="txtbox" />
Is there a way a way to access the "Company" value and change it programmatically, or do I simply change the value of the textbox and It will update accordingly?
Check links below:
http://mrbool.com/two-way-data-binding-course-asp-net-4-and-visual-studio-2010-part-46/22435
http://www.ccopus.com/blog/article.asp?id=24
You can see the same question here
Related
I use PNM Sequence. And I need to make one grid column as the mandatory field.
I know how to make it with any separate control. E.g. I can type:
<sq8:GridBoundColumn DataField="txtField" HeaderText="txtField"
SortExpression="txtField" UniqueName="txtField" FilterControlAltText="">
<ColumnValidationSettings>
<RequiredFieldValidator ForeColor=""></RequiredFieldValidator>
</ColumnValidationSettings>
</sq8:GridBoundColumn>
And I can use this Validator for the TextBox:
<sq8:Label runat="server" Text="Field:" ID="Label1" Width="100%"></sq8:Label>
<nobr>
<sq8:TextBox runat="server" ID="txtField" Width="100%"></sq8:TextBox>
<sq8:RequiredFieldValidator runat="server"
ErrorMessage="RequiredFieldValidator"
ID="RequiredFieldValidator4"
ControlToValidate="txtField"
SetFocusOnError="True">*</sq8:RequiredFieldValidator>
</nobr>
<sq:BindableControl runat="server" TargetControlID="txtField"
DataField="txtField"></sq:BindableControl>
And it works. User can't send the form because he gets an error - the field is empty.
But I need to do the same with grid.
When I open "Edit columns" in Grid Wizard I can't see any property as "mandatory" or something like this.
And the code with RequiredFieldValidator doesn't work with a grid column. If I try to use it:
<Columns>
<sq8:GridBoundColumn DataField="txtFieldGrid" HeaderText="txtFieldGrid"
SortExpression="txtFieldGrid" UniqueName="txtFieldGrid"
FilterControlAltText="">
<sq8:RequiredFieldValidator runat="server"
ErrorMessage="RequiredFieldValidator"
ID="RequiredFieldValidator4"
ControlToValidate="txtFieldGrid"
SetFocusOnError="True">*</sq8:RequiredFieldValidator>
<sq:BindableControl runat="server" TargetControlID="txtFieldGrid"
DataField="txtFieldGrid"></sq:BindableControl>
</sq8:GridBoundColumn>
</Columns>
In this case, I have an error:
Is there some method for grid column validation? Or it's impossible with a grid?
Maybe I can use some javascript?
i want to know status is active or not in check box. how to bind check box with database data. while editing im lossing previous data. data is not showing in check box
code behind updating event
cmd.Parameters.AddWithValue("#LeadsAccess", ChkLeads.Checked);
<asp:TemplateField HeaderText="Leads">
<ItemTemplate>
<asp:CheckBox ID="ChkLeads" runat="server" />
</ItemTemplate>
</asp:TemplateField>
db column- [Leads]
You can try like this
<asp:CheckBox ID="ChkLeads" runat="server"
Checked='<%#bool.Parse(Eval("columnName").ToString())%>' />
try this..
you can bind the db value like this..
<asp:CheckBox ID="ChkLeads" runat="server" AutoPostBack="true" Checked='<%#Convert.ToBoolean(Eval("LeadsAccess"))%>'/>
i'm loosing my mind. Using ASP.NET in a GridView, amongst other controls, I have the following:
<asp:TemplateField HeaderText="Intention">
<EditItemTemplate>
<asp:TextBox ID="IntentionInfo" Enabled="true" TextMode="MultiLine" Wrap="true" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="IntentionInfo" Enabled="false" TextMode="MultiLine" runat="server" />
</ItemTemplate>
</asp:TemplateField>
I would like to take the value out of this textarea and save in a database. However, server side, I try to pull the value out, like such:
string txt = (TextBox)DonationResultsTable.Rows[e.RowIndex].Cells[6].Controls[1].Text;
... but I keep getting the value that was SENT to the Client.
I wrote this javascript and I can see the values change in the DOM, but still the server keeps taking the old value.
$("textarea").change(function()
{
var txt = $(this).val();
$(this).html(txt).text(txt);
});
So my guess was ViewState, but I disabled it for those controls, like this:
<asp:TextBox ID="IntentionInfo" ViewStateMode="Disabled" Enabled="false" TextMode="MultiLine" runat="server" />
Still nothing! Any ideas?
One option could be to use a hidden field and update it on text changed for the text area. You could do this with jQuery like this:
$("textarea[id$=tbTest]").change(function () {
$("input[id$=hdnVal]").val($("textarea[id$=tbTest]").val());
});
Then on the server side, you can retrieve the hidden field's value and save it to your database.
Im populating a GridView from List so am forced to use TemplateField controls to allow editing. This requires displaying a TextBox populated with the original value when in edit mode and using FindControl to get the new value out on update submit.
Problem is foundTextBox.Text == "OriginalTextBoxValue"
<asp:TemplateField HeaderText="A Field">
<ItemTemplate>
<asp:Label ID="_theLabel" runat="server" Text='<%# Eval("AField") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="_theTextBox" runat="server" Text='<%# Eval("AField") %>' />
</EditItemTemplate>
</asp:TemplateField>
And the code in my update event handler
TextBox newText = (TextBox)_myGridView.Rows[e.RowIndex].FindControl("_thTextBox");
//newText.Text == the old value of the text box
Is your gridview binded at every postback? This could explain why you never get the updated value, because the gridview is rebinded before reading the textbox.
Could you paste your complete update method?
You've got the code behind in the wrong event handler. Move it to the Editing event handler, so it will populate the textbox whenever the user clicks on the Edit command for a row.
I'm working on an ASP.NET page, and have a DataList with a non-visible label, ID, inside of it. The Datalist is populated by Query A.
I'm trying to add a handler in my VB code where it will run Query B, populating a different label in the Item Template, after ID is changed. I figure I need to go somewhere in the DataList, but poking through Intellisense and a google search weren't successful. Does anyone know how I get to that label? Sorry if this is a dumb question, and thanks for the help.
Edit: I see how I can access the datalist items while inside the function, but how do I do it for only one part of the DataList control in the Event Handler? All the options I'm seeing are related to full events involving the Data List, not a single label changing. Thanks.
Edit 2:
I figured I'd add some code, to better explain exactly the exact issue I'm having.
<asp:DataList ID="DataList1" runat="server" DataSourceID="Omitted,Ilikemyjob">
<ItemTemplate>
<asp:Label ID="FromLabel" runat="server" Font-Size="Small" Text='<%# Eval("IncdntDate") %>'></asp:Label><br />
<asp:Label ID="ToLabel" runat="server" Font-Size="Small" Text='<%# Eval("Roadway") %>'></asp:Label><br />
<asp:Label ID = "lblCrossroad" runat ="server" Font-Size = "Small" Text = '<%# Eval("Crossroad") %>'></asp:Label><br />
<asp:Label ID = "lblRdwyID" runat ="server" Font-Size="Small" Visible = "false" Text = '<%# Eval ("RdwyID") %>'></asp:Label>
<asp:Label ID = "DistanceLabel" runat ="server" Font-Size = "Small" Text = '<%# Eval("RptTime") %>'></asp:Label><br />
<asp:Label ID = "lblTTime" runat ="server" Font-Size = "small" visible ="false"></asp:Label>
<hr />
</ItemTemplate>
</asp:DataList><br />
There's the DataList thing I'm doing, and I have a different query that I want to store the value of to lblTTime if lblRdwyID is set to a certain range of values, thought it will not always be set to a value.
I'm trying to set up an event that will trigger when lblRdwyID is set, that will launch the other query and set the value of that templated items lblTTime and make it visible. Is there a good way to do this? I tried messing around with DataList1's events, but couldn't get anything to do the trick.
If your label has its visibility set to false, it won't render on the screen (as opposed to having a div block with visibility set to hidden), and so I wager that is why you can't actually find the control after the binding has occurred.
Have you tried using the DataKey property to store the ID instead? It is easily accessible at the row level and you can store additional data if needs be.
Assuming you have the row, you use:
row.FindControl("mylabelid")