Saturday, March 31, 2012
Set border width for datagrid
I have a dropdown and want the user to toggle border width or alternating
color etc for datagrid.
How can i implement this in codebehind?
Thanks
MannyUse the property AlternatingItemStyle
Cheers,
Gaurav Vaish
http://mastergaurav.org
--
Monday, March 26, 2012
Set Dropdown List Default Text
Is it possible to have a dropdown list that when the page is first
visited has a selected value of something like "Choose an Option". After the
user has selected an option the the user should not be able to selected the
default value an more. If this is possible could somebody show me a same in
C#.
Thanks
KennethThere are several ways to do that. One would be the SelectedIndexChanged
event. When the event occurs, check the value of the selected item. If it is
the text you don't want selected, remove that item. However, I would suggest
using a validator. The two best candidates would be the
RequiredFieldValidator and the CompareValidator.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Kenneth Keeley" <kenkeeley@.hotmail.com> wrote in message
news:uFCCiVYvFHA.1436@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is it possible to have a dropdown list that when the page is first
> visited has a selected value of something like "Choose an Option". After
> the
> user has selected an option the the user should not be able to selected
> the
> default value an more. If this is possible could somebody show me a same
> in
> C#.
> Thanks
> Kenneth
Set Dropdown List Default Text
Is it possible to have a dropdown list that when the page is first
visited has a selected value of something like "Choose an Option". After the
user has selected an option the the user should not be able to selected the
default value an more. If this is possible could somebody show me a same in
C#.
Thanks
KennethThere are several ways to do that. One would be the SelectedIndexChanged
event. When the event occurs, check the value of the selected item. If it is
the text you don't want selected, remove that item. However, I would suggest
using a validator. The two best candidates would be the
RequiredFieldValidator and the CompareValidator.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Kenneth Keeley" <kenkeeley@.hotmail.com> wrote in message
news:uFCCiVYvFHA.1436@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is it possible to have a dropdown list that when the page is first
> visited has a selected value of something like "Choose an Option". After
> the
> user has selected an option the the user should not be able to selected
> the
> default value an more. If this is possible could somebody show me a same
> in
> C#.
> Thanks
> Kenneth
>
Set Focus
Thank youYou need to add some clientside JavaScript code in the form of an onchange event handler.
OTTOMH, something like:
DDL.attributes.add("onchange","document.getElementById('controlId').focus()")
Saturday, March 24, 2012
Set Focus and post back on Dropdown List
The focus remains on the dropdown list after the postback and I am trying to get it away from it because the user may and does want to use the mouse wheel to scroll down, but since the focus is on the ddl, they may not see it and it will resort.
Here is my set focus code which works fine on page load event...
Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"
RegisterStartupScript("focus", s)
End Sub
And this code is for the page load event...
If Not IsPostBack Then
Me.SetFocus(Me.txtSearch)
End If
I have been trying to place the Me.SetFocus(Me.txtSearch) where the postback of the ddl occurs in the code, such as the reBind() or the ddlTypes_SelectedIndexChanged() and the dgServer_ItemDataBound() which has the ddl code.
None seem to work, but it works on page load event.
Suggestions?
Thanks all,
Zath
This should work fine from your ddlTypes_SelectedIndexChanged() event handler. Are calling this method only if the IsPostBack property is false? If so, that could be your problem.
Have you tried putting the SetFocus in the Page_PreRender? This runs after the event code.
Private Sub Page_PreRender(ByVal sender AS Object,VyVal e AS System.EventArgs) Handles MyBase.PreRender
If ispostback=true then
Me.SetFocus(Me.txtSearch)
End if
End Sub
You can use
If Not ispostback
if necessary.
check out my component here :view post 821121
regards
Set focus to DAtagrid Cell
columns with Dropdown lists. My Third column as databound cell. When I go
to edit a particular row I want the focus to change to the third row. I am
using Visual Studio VB.Net with WEB Forms. Any Help would be great.It is not clear what exactly you want. Anyway, setting focus is a
client-side task. You have to produce some javascript which will operate on
the client DHTML presentation of the grid.
Eliyahu
"rroca" <oeb@.homexperts.net> wrote in message
news:C3CD2487-6FD7-4830-A20D-E14E18CA56F1@.microsoft.com...
> I hae a WEB application that uses a datagrid. My first 2 rows are
Template
> columns with Dropdown lists. My Third column as databound cell. When I
go
> to edit a particular row I want the focus to change to the third row. I
am
> using Visual Studio VB.Net with WEB Forms. Any Help would be great.
Set focus to DAtagrid Cell
columns with Dropdown lists. My Third column as databound cell. When I go
to edit a particular row I want the focus to change to the third row. I am
using Visual Studio VB.Net with WEB Forms. Any Help would be great.It is not clear what exactly you want. Anyway, setting focus is a
client-side task. You have to produce some javascript which will operate on
the client DHTML presentation of the grid.
Eliyahu
"rroca" <oeb@.homexperts.net> wrote in message
news:C3CD2487-6FD7-4830-A20D-E14E18CA56F1@.microsoft.com...
> I hae a WEB application that uses a datagrid. My first 2 rows are
Template
> columns with Dropdown lists. My Third column as databound cell. When I
go
> to edit a particular row I want the focus to change to the third row. I
am
> using Visual Studio VB.Net with WEB Forms. Any Help would be great.
Tuesday, March 13, 2012
set selected value declaratively to dropdownlist
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
</EditItemTemplate>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any promptsHi,
You can set the selectedvalue property on the dropdownlist as follows
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddl"
DataSourceID="SqlDataSource2"
DataValueField="ProductID"
DataTextField="ProductName" SelectedValue='<%# Bind("ProductID")
%>'></asp:DropDownList>
</EditItemTemplate>
Regards,
Mohamed Mosalem
"podi" wrote:
> Hi,
> I just wonder if there is a way to set a selected item in dropdown list
> which items are retreived from database without touching c# code ?
> I mean, i have in gridview, in edit mode one dropdownlist which
> selected value should be the same as a label text from normal view mode
> <EditItemTemplate>
> <asp:DropDownList ID="ddlGrdvFrequency" runat="server"
> DataTextField="Frequency"
> DataValueField="FrequencyId"
> DataSourceID="SqlDataSourceMembershipFrequency" />
> </EditItemTemplate>
> I was looking for sth like SelectedIndex, but intellisense did not give
> me any prompt for it. I use now C# code in databound event for gridview
> to set this item selected, but ...is there a way of not using this ?
> thanks for any prompts
>
hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.
i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim
"podi" <lukasz.podolak@.gmail.com> wrote in message
news:1159037422.462578.221520@.d34g2000cwd.googlegroups.com...
> Hi,
> I just wonder if there is a way to set a selected item in dropdown list
> which items are retreived from database without touching c# code ?
> I mean, i have in gridview, in edit mode one dropdownlist which
> selected value should be the same as a label text from normal view mode
> <EditItemTemplate>
> <asp:DropDownList ID="ddlGrdvFrequency" runat="server"
> DataTextField="Frequency"
> DataValueField="FrequencyId"
> DataSourceID="SqlDataSourceMembershipFrequency" />
> </EditItemTemplate>
> I was looking for sth like SelectedIndex, but intellisense did not give
> me any prompt for it. I use now C# code in databound event for gridview
> to set this item selected, but ...is there a way of not using this ?
> thanks for any prompts
>
Thank you for responses, it helped
Tim_Mac wrote:
> hi podi,
> unfortunately the SelectedIndex cannot be set declaratively, it is a compi
le
> error. i'm just wondering how you could know in advance with a databound
> list which one to select?
> an alternative would be to sort the datasource so that the one you want to
> select is the first record, then it will be selected by default when the
> list is databound.
> i think the databound event is the correct (and best) place to achieve you
r
> task.
> i hope this helps
> tim
>
> "podi" <lukasz.podolak@.gmail.com> wrote in message
> news:1159037422.462578.221520@.d34g2000cwd.googlegroups.com...
set selected value declaratively to dropdownlist
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
</EditItemTemplate>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any promptsHi,
You can set the selectedvalue property on the dropdownlist as follows
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddl"
DataSourceID="SqlDataSource2"
DataValueField="ProductID"
DataTextField="ProductName" SelectedValue='<%# Bind("ProductID")
%>'></asp:DropDownList>
</EditItemTemplate>
Regards,
Mohamed Mosalem
"podi" wrote:
Quote:
Originally Posted by
Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
>
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
>
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
>
</EditItemTemplate>
>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts
>
>
hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.
i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim
"podi" <lukasz.podolak@.gmail.comwrote in message
news:1159037422.462578.221520@.d34g2000cwd.googlegr oups.com...
Quote:
Originally Posted by
Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
>
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
>
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
>
</EditItemTemplate>
>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts
>
Thank you for responses, it helped
Tim_Mac wrote:
Quote:
Originally Posted by
hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.
>
i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim
>
>
>
"podi" <lukasz.podolak@.gmail.comwrote in message
news:1159037422.462578.221520@.d34g2000cwd.googlegr oups.com...
Quote:
Originally Posted by
Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
</EditItemTemplate>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts