RadDatePicker in ASP.NET Gridview TemplateField - asp.net

I've got a date picker field declared within a template field in a GridView as follows:
<asp:TemplateField HeaderText="Shipping Date">
<ItemTemplate>
<asp:Label ID="lblShippingDate" runat="server" CssClass="dnnFormLabel"
AssociatedControlID="ShippingDatePicker" />
<dnn:DnnDatePicker runat="server" ID="ShippingDatePicker" />
</ItemTemplate>
</asp:TemplateField>
I can select the date just fine and it appears in my label control - I then click on a standard asp:Button which finds the selected row and despite it finding all the other controls on the row including the label control displaying the selected date, the label's Text attribute is blank:
var txtShippingDate = row.Cells[7].FindControl("lblShippingDate") as Label;
Please note that I'm using the DotNetNuke dnn:DnnDatePicker control but this is actually a RadDatePicker under the covers.
Can anyone suggest how I can successfully read the value?
Thanks for looking :)

Try following after you find label:
if(txtShippingDate != null) {
string date = Request.Form[txtShippingDate.UniqueID].ToString();
}

Related

getting the RadGrid checkbox column value in server

I have a RadGrid having a checkbox column, i have added the column as a ItemTemplate to make it editable in the regular mode.
<telerik:GridTemplateColumn UniqueName="IsSelected" DataField="IsSelected">
<ItemTemplate>
<asp:CheckBox ID="chkBoolean" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsSelected")) %>'Enabled='<%# Convert.ToBoolean(Eval("IsSelectionDisable")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
Using this I am able to display a checkbox as editable. Now my problem is how do i get the checked value of the checkox for saving it when the user has changed the checkbox. On click of a button i need to get all the rows that are still checked and save them. The below code does not work as it does not get the checkbox. Is there any way possible to get the value.
foreach (GridDataItem item in rgUnavailResult.MasterTableView.Items)
{
(CheckBox)item["IsSelected"].Controls[0]
}
Thanks
Found the checkbox
((System.Web.UI.WebControls.CheckBox)(item["IsSelected"].FindControl("chkBoolean")))

How can I disable/hide edit button in gridview control of ASP.net

I have a gridview control in which there are two command buttons (linkButton), one is "select" and the other is "edit", now I have a session variable named as department and it contains values like "WRITING", "EDITING", "ADMIN" etc... Now the thing is I want the edit button to disappear when the department is "WRITING" but when it is "EDITING" or "ADMIN" I want edit button appear.
I was searching some forums for this problem and found this
row.Cells[0].Controls.Clear();
The problem with this code is that it hides the entire command column including "select" and "edit" buttons while I only want to control "edit" button, select should remain visible for all departments.
if I do it like (on row data bound event)
e.row.Cells[0].Controls[1].visible = false OR
e.row.Cells[0].Controls[0].visible = false
Specified argument was out of the range of valid values.
How can I do this properly ?
Thanks.
You can use the Visible property in the following way.
if (Session(mode) == "WRITING")
{
(e.Row.FindControl("btnEdit")).Visible = false;
}
First of all - your code does not work because your gridViewCell at index 0 contains only one control. Every CommandButton gets a single cell! Furthermore I am not quite sure why you make use of the RowDataBound event. As you are using a Session-Var this one may not change while binding your rows.
I tried the following piece of code in my pageLoad eventHandler - and it worked out for me:
/// just replace CAPITAL letters with your names and
/// (Session["department"] == "WRITING") with your boolean expression
gvYOURGV.Columns[INDEXOFSELECTCOLUMN].Visible = (Session["department"] == "WRITING");
In case you do want to have (need to have?) more flexibilty on modifying the appearance of your command columns - you may even consider, changing your command columns to templated columns. Doing so you may have the possibility for this code:
<asp:GridView ID="gvYOURGV" runat="server">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
visible='<%# Session["department"] != "WRITING" %>'
runat="server" CausesValidation="False"
CommandName="Select" Text="Auswählen"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
hth

FindControl("someTextBox") in GridView not sending the updated value

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.

asp.net HyperLinkField Has no ToolTip property (Alt text)

I wish there was a ToolTip field in HyperLinkField as there is one in HyperLink.
I'm creating a HyperLinkField by code before binding to my data source:
HyperLinkField hl = new HyperLinkField();
hl.DataNavigateUrlFields = new string[] { "col" };
hl.DataNavigateUrlFormatString = "{0}";
hl.DataTextField = "Foo";
Is there any way to also set a value to something which will render as a tooltip (or alt text)?
Any help will be appreciated.
That's correct, there's no tooltip/alt text property in a HyperlinkField. To get around this shortcoming, you need to use a template field and add a regular Hyperlink control.
<asp:TemplateField HeaderText="Href">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#
Eval("Href") %>' Text='<%# Eval("Href") %>' ToolTip='<%# Eval("Text") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
However, doing this in a programmatic requires a lot of work. You need to create your own class that implements the ITemplate interface. Here's a tutorial on that.
Your requirement can be accompished in <asp:HyperlinkField> itself by adding tooltip for that specific cell in RowDataBound event of a GridView. After binding the GridView to your DataSource you can do this in a RowDataBound event as follows:
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].ToolTip = "Your tooltip text";
}
Though you have accepted another answer, my answer may be helpful for some other users!

How to find checked RadioButton inside Repeater Item?

I have a Repeater control on ASPX-page defined like this:
<asp:Repeater ID="answerVariantRepeater" runat="server"
onitemdatabound="answerVariantRepeater_ItemDataBound">
<ItemTemplate>
<asp:RadioButton ID="answerVariantRadioButton" runat="server"
GroupName="answerVariants"
Text='<%# DataBinder.Eval(Container.DataItem, "Text")%>'"/>
</ItemTemplate>
</asp:Repeater>
To allow select only one radio button in time I have used a trick form this article.
But now when form is submitted I want to determine which radio button is checked.
I could do this:
RadioButton checkedButton = null;
foreach (RepeaterItem item in answerVariantRepeater.Items)
{
RadioButton control=(RadioButton)item.FindControl("answerVariantRadioButton");
if (control.Checked)
{
checkedButton = control;
break;
}
}
but hope it could be done somehow simplier (maybe via LINQ to objects).
You could always use Request.Form to get the submitted radio button:
var value = Request.Form["answerVariants"];
I think the submitted value defaults to the id of the <asp:RadioButton /> that was selected, but you can always add a value attribute - even though it's not officially an <asp:RadioButton /> property - and this will then be the submitted value:
<asp:RadioButton ID="answerVariantRadioButton" runat="server"
GroupName="answerVariants"
Text='<%# DataBinder.Eval(Container.DataItem, "Text")%>'"
value='<%# DataBinder.Eval(Container.DataItem, "SomethingToUseAsTheValue")%>' />
Since You are using javascript already to handle the radio button click event on the client, you could update a hidden field with the selected value at the same time.
Your server code would then just access the selected value from the hidden field.
I'm pretty sure that the only thing you could use LINQ to Objects for here would be to take the conditions from within the foreach loop and move them to a where clause.
RadioButton checked =
(from item in answerVariantRepeater.Items
let radioButton = (RadioButton)item.FindControl("answerVariantRadioButton")
where radioButton.Checked
select radioButton).FirstOrDefault();

Resources