Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Saturday, March 31, 2012

the best way display data from dropdownlist?

OK..i have a field called - areaID,

i would like to make it to display areaNAME instead of ID, so a human can understand.

What i have done:

1. Converted that field into template;

2. For Edit mode - i made drop down list where a user can choose areaName instead of areaID, though areaID is bounded to the field.

3. For Item mode - ? my question:

i don't want to make the same dropdown list display, it looks not appropriate, - i would like to have 'label' like component to display my areaName on areaID field, how to do it?

I could probably create some function or stored procedure to return areaName, and as a parameter use areaID, but i don't want to complecate matters too much...

I know it had been done 100 times...but not by me...

anyone can give a hint?

thanks for your help!!

I'm not sure why you wouldn't just return the areaname in the query/sp that fills the grid, and use a Label or Literal in your ItemTemplate. After all, the value for that row doesn't really come from the dropdownlist; it comes from the datasource for the parent control.


Hi Peter, I think I have the same issue in that I would like to display descriptive names for domain data in the ItemTemplate, but in order to bind a dropdown in the EditTempate I also need the ID field. Are you suggesting having both the IDand description fields available in the datasource and then binding ItemTemplate label to the description field and the EditTemplate dropdown to the ID field? Sorry if I'm slow, I'm new to .NET in general


Thanks,

- Ben


I am not sure you are asking the right question, because it sounds like you are using a GridView, or other data control. But dropdowns have two properties, DataTextField and dataValueField where you set the field names to display in a drop-down.

That's not what I'm getting at; In a FormView I would like to show a label control in the "view" mode (ItemTemplate) and switch to a dropdown control in the "edit" mode (EditTemplate). My data table currently stores only the ID/foreign key of the domain table as it has been normalized. Now, this arrangement works perfectly with the dropdown as it is populated with the domain dataset and then it's selected row is bound to the ID field in my formview's dataset. Fine.

But in "view" mode I want to add alabel control that shows the user-friendly descriptive text from the domain table instead of a cryptic ID. As stated by the original poster, I could always write a function to "lookup" the domain description using the ID as a key but I'm thinking that's not the in the spirit of the declarative syntax and it's not efficient.

What I think was proposed was to join to the domain table in my source query and get the domain description and have it available along with the ID so I can bind to either one as needed. Was that the idea?


Yes, that's it. Just join on the ID field and pull the name as part of your datasource.


Thanks!

Monday, March 26, 2012

The conversion of a char data type to a datetime data type resulted....

Hi,

I'm trying to insert a date time value into a SQL Server Database field of type date time using a c# web form.
I get the following error...
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated"

My SQL looks like this:


INSERT INTO tblname (fldname) VALUES ('" + DateTime.Now.ToString() + "')"

What am I doing wrong?Remove the ToString() method as that is changing the DateTime type to a string (or Char type) ...at least thats what it looks like.
Nope sorry to say that didn't work.

My C# now looks like


SqlConnection myConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["eTeam_ConnectionString"].ToString());
string mySQL = "INSERT INTO tblname (datestamp) VALUES ('" + DateTime.Now + "')";
SqlCommand myCMD = new SqlCommand(mySQL, myConn);
myConn.Open();
myCMD.ExecuteNonQuery();
myConn.Close();
myCMD.Dispose();
myConn.Dispose();

And the field 'datestamp' is a SQL Server Data Type datetime

Anyone else?
You can use getDate() method of SQL server to update date.

INSERT INTO tblname (datestamp) VALUES (getDate())";
Thanks for that - definately half way to solving my problem.
What if I need to take a value from an ASP:Calendar control?
Is there a ToDate() function that will convert it as required?
You can use

Calendar1.SelectedDate.ToShortDateString())

which will convert this date into short date format.

Tuesday, March 13, 2012

The link button is not showingcorrect

I have a datalist. This is the code.
I have 2linkbuttons and it depends of a field to show one or the other.
The IF clause is OK, but its showing me the links in BLACK not in blue! and
they are like plain text not links.
asp:DataList id="dlsolicitud" runat="server" Width="800px"
GridLines="Both" CellPadding="4" BorderColor="#CC9966"
BackColor="White" BorderStyle="None" BorderWidth="1px">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<HeaderTemplate>
<TABLE id="Table2" runat="server" borderColor="#000000"
cellSpacing="1" cellPadding="1"
width="800" border="1" runat="server">
<TR>
<TD width="30">Id</TD>
<TD width="200">Nombre</TD>
<TD width="50">Prioridad</TD>
<TD width="500">Diagnostico</TD>
<TD width="50">Estadl</TD>
<TD width="20"></TD>
</TR>
</TABLE>
</HeaderTemplate>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<ItemTemplate>
<TABLE id="Table2" borderColor="#000000" cellSpacing="1"
cellPadding="1" width="800" border="1"
runat="server">
<TR>
<TD width="30"><%# DataBinder.Eval(Container,
"DataItem.idserviciomantenimiento") %></TD>
<TD width="200"><%# DataBinder.Eval(Container,
"DataItem.nombre") %></TD>
<TD width="50"><%# DataBinder.Eval(Container,
"DataItem.prioridad") %></TD>
<TD width="500"><%# DataBinder.Eval(Container,
"DataItem.diagnostico") %></TD>
<TD width="50"><%# DataBinder.Eval(Container, "DataItem.estado")
%></TD>
<TD width="20">
<asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
CommandName="Ejecutar">Ejecutar</asp:linkbutton>
<asp:linkbutton Runat="server" ID="finalizar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
CommandName="Finalizar">Finalizar</asp:linkbutton>
</TD>
</TR>
</TABLE>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
</asp:DataList>
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 1.
MIEMBRO ACTIVO DE ALIANZADEVfor an anchor (what a link button renders as), you need to set the following
styles:
a :visted
a :link
a :active
a :hover
to control the display
-- bruce (sqlwork.com)
"Luis Esteban Valencia" <luisvalen@.haceb.com> wrote in message
news:uF2ZcbRkEHA.556@.tk2msftngp13.phx.gbl...
> I have a datalist. This is the code.
> I have 2linkbuttons and it depends of a field to show one or the other.
> The IF clause is OK, but its showing me the links in BLACK not in blue!
and
> they are like plain text not links.
> asp:DataList id="dlsolicitud" runat="server" Width="800px"
> GridLines="Both" CellPadding="4" BorderColor="#CC9966"
> BackColor="White" BorderStyle="None" BorderWidth="1px">
> <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
> BackColor="#FFCC66"></SelectedItemStyle>
> <HeaderTemplate>
> <TABLE id="Table2" runat="server" borderColor="#000000"
> cellSpacing="1" cellPadding="1"
> width="800" border="1" runat="server">
> <TR>
> <TD width="30">Id</TD>
> <TD width="200">Nombre</TD>
> <TD width="50">Prioridad</TD>
> <TD width="500">Diagnostico</TD>
> <TD width="50">Estadl</TD>
> <TD width="20"></TD>
> </TR>
> </TABLE>
> </HeaderTemplate>
> <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
> <ItemTemplate>
> <TABLE id="Table2" borderColor="#000000" cellSpacing="1"
> cellPadding="1" width="800" border="1"
> runat="server">
> <TR>
> <TD width="30"><%# DataBinder.Eval(Container,
> "DataItem.idserviciomantenimiento") %></TD>
> <TD width="200"><%# DataBinder.Eval(Container,
> "DataItem.nombre") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
> "DataItem.prioridad") %></TD>
> <TD width="500"><%# DataBinder.Eval(Container,
> "DataItem.diagnostico") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
"DataItem.estado")
> %></TD>
> <TD width="20">
> <asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
> CommandName="Ejecutar">Ejecutar</asp:linkbutton>
> <asp:linkbutton Runat="server" ID="finalizar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
> CommandName="Finalizar">Finalizar</asp:linkbutton>
> </TD>
> </TR>
> </TABLE>
> </ItemTemplate>
> <FooterStyle ForeColor="#330099"
BackColor="#FFFFCC"></FooterStyle>
> <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
> BackColor="#990000"></HeaderStyle>
> </asp:DataList>
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 1.
> MIEMBRO ACTIVO DE ALIANZADEV
>

The link button is not showingcorrect

I have a datalist. This is the code.
I have 2linkbuttons and it depends of a field to show one or the other.

The IF clause is OK, but its showing me the links in BLACK not in blue! and
they are like plain text not links.

asp:DataList id="dlsolicitud" runat="server" Width="800px"
GridLines="Both" CellPadding="4" BorderColor="#CC9966"
BackColor="White" BorderStyle="None" BorderWidth="1px">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<HeaderTemplate>
<TABLE id="Table2" runat="server" borderColor="#000000"
cellSpacing="1" cellPadding="1"
width="800" border="1" runat="server">
<TR>
<TD width="30">Id</TD>
<TD width="200">Nombre</TD>
<TD width="50">Prioridad</TD>
<TD width="500">Diagnostico</TD>
<TD width="50">Estadl</TD>
<TD width="20"></TD>
</TR>
</TABLE>
</HeaderTemplate>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<ItemTemplate>
<TABLE id="Table2" borderColor="#000000" cellSpacing="1"
cellPadding="1" width="800" border="1"
runat="server">
<TR>
<TD width="30"><%# DataBinder.Eval(Container,
"DataItem.idserviciomantenimiento") %></TD>
<TD width="200"><%# DataBinder.Eval(Container,
"DataItem.nombre") %></TD>
<TD width="50"><%# DataBinder.Eval(Container,
"DataItem.prioridad") %></TD>
<TD width="500"><%# DataBinder.Eval(Container,
"DataItem.diagnostico") %></TD>
<TD width="50"><%# DataBinder.Eval(Container, "DataItem.estado")
%></TD>
<TD width="20">
<asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
CommandName="Ejecutar">Ejecutar</asp:linkbutton>
<asp:linkbutton Runat="server" ID="finalizar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
CommandName="Finalizar">Finalizar</asp:linkbutton>
</TD>
</TR>
</TABLE>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
</asp:DataList
--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 1.
MIEMBRO ACTIVO DE ALIANZADEVfor an anchor (what a link button renders as), you need to set the following
styles:

a :visted
a :link
a :active
a :hover

to control the display

-- bruce (sqlwork.com)

"Luis Esteban Valencia" <luisvalen@.haceb.com> wrote in message
news:uF2ZcbRkEHA.556@.tk2msftngp13.phx.gbl...
> I have a datalist. This is the code.
> I have 2linkbuttons and it depends of a field to show one or the other.
> The IF clause is OK, but its showing me the links in BLACK not in blue!
and
> they are like plain text not links.
> asp:DataList id="dlsolicitud" runat="server" Width="800px"
> GridLines="Both" CellPadding="4" BorderColor="#CC9966"
> BackColor="White" BorderStyle="None" BorderWidth="1px">
> <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
> BackColor="#FFCC66"></SelectedItemStyle>
> <HeaderTemplate>
> <TABLE id="Table2" runat="server" borderColor="#000000"
> cellSpacing="1" cellPadding="1"
> width="800" border="1" runat="server">
> <TR>
> <TD width="30">Id</TD>
> <TD width="200">Nombre</TD>
> <TD width="50">Prioridad</TD>
> <TD width="500">Diagnostico</TD>
> <TD width="50">Estadl</TD>
> <TD width="20"></TD>
> </TR>
> </TABLE>
> </HeaderTemplate>
> <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
> <ItemTemplate>
> <TABLE id="Table2" borderColor="#000000" cellSpacing="1"
> cellPadding="1" width="800" border="1"
> runat="server">
> <TR>
> <TD width="30"><%# DataBinder.Eval(Container,
> "DataItem.idserviciomantenimiento") %></TD>
> <TD width="200"><%# DataBinder.Eval(Container,
> "DataItem.nombre") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
> "DataItem.prioridad") %></TD>
> <TD width="500"><%# DataBinder.Eval(Container,
> "DataItem.diagnostico") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
"DataItem.estado")
> %></TD>
> <TD width="20">
> <asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
> CommandName="Ejecutar">Ejecutar</asp:linkbutton>
> <asp:linkbutton Runat="server" ID="finalizar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
> CommandName="Finalizar">Finalizar</asp:linkbutton>
> </TD>
> </TR>
> </TABLE>
> </ItemTemplate>
> <FooterStyle ForeColor="#330099"
BackColor="#FFFFCC"></FooterStyle>
> <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
> BackColor="#990000"></HeaderStyle>
> </asp:DataList>
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 1.
> MIEMBRO ACTIVO DE ALIANZADEV