Link to home
Create AccountLog in
Avatar of nguyenvinhtu
nguyenvinhtu

asked on

Question on ASP.NET

I am currently making a Manual Payrolling on ASP.NET, what I have to do is showing the payroll table which shape as below.
1 - I call the store procedure to return the table shape like below table.
2 - I bind the Grid to Datasource. Then the table will contain the data like the following table.
3 - On Page I have the code snippet:
<asp:TextBox id=txtDay1 Text='<%# DataBinder.Eval(Container, "DataItem.Day01")%>' >
...
<asp:TextBox id=txtDay1 Text='<%# DataBinder.Eval(Container, "DataItem.Day31")%>' >

|   EmpID    |    March 1    |     March 2    |    ...   |  March 31  |
|   00001    |        8          |       02          |    ...   |       8         |          8 -> Work hour
|   00002    |        02        |       02          |    ...   |       8         |         02 -> Absense code

In the table we will have 8 as "hours of work" and 02 is the "absense code".
My validation on the table is that the user can correct the "work hours", but not on the "absent code". So, the textfield which contain "absense code" should be disabled.

First, Is there any recommedation to quickly solve the problem as I presented above? But it should be adaptable on other situation, for instance, if the user want the absence code to be text like "Absence" or else.
I think I prefer the second way.

The second way is to change the stored procedure/function, that the stored procedure will return a table with data
|   EmpID    |    March1             |     March2              |    ...   |  March31             |
|   00001    |        8$True          |       02$False          |    ...   |       8$True         |          8 -> Work hour
|   00002    |        02$False       |       02$False          |    ...   |       8$True         |         02 -> Absense code

Then on Binding to DataGrid. That means
DataBinder.Eval(Container, "DataItem.Day01") will result 8$True
DataBinder.Eval(Container, "DataItem.Day02") will result 02$False

My idea is to split 8$True into 2 parts like
string[] strA = "8$True".Split("$");
strA[0] = 8
strA[1] = True
so that I can have
<asp:TextBox id=txtDay1 Text='<%#
                                                      {[DataBinder.Eval(Container, "DataItem.Day01")].Split("$")}[0]
                                              %>'
                                     Enabled='<%#
                                                      {[DataBinder.Eval(Container, "DataItem.Day01")].Split("$")}[1]
                                              %>' >
that when Page loaded.
<asp:TextBox id=txtDay1 Text='8' Enabled=True >
<asp:TextBox id=txtDay1 Text='02' Enabled=False >

But I cannot write the code on page.
Hope you understand my idea, I tried a lot.
Thanks and Regards
Avatar of t_itanium
t_itanium
Flag of United Arab Emirates image

hi
before you change the value in the textbox store its value in atemp variable...then check if it is an abscence code...return the old value to the text box else put the new value..
cheers
Avatar of nguyenvinhtu
nguyenvinhtu

ASKER

Hi everyone, thanks for commenting my question. Now I got a solution for my question.
I don't use Split function but a combination of Substring() and IndexOf(). I'll show you the answer.

<asp:TextBox id=txtDay1
     Enabled='<%# Convert.ToBoolean(
                                       Convert.ToString(
                                                  DataBinder.Eval(Container, "DataItem.Day01")
                                       ).Substring(
                                             Convert.ToString(DataBinder.Eval(Container, "DataItem.Day01")).IndexOf("$")+1)
                                         ) %>'
     Text='<%# Convert.ToString(
                                                  DataBinder.Eval(Container, "DataItem.Day01")
                                       ).Substring(
                                             0,Convert.ToString(DataBinder.Eval(Container, "DataItem.Day01")).IndexOf("$"))
%>' Runat="server">

The answer is rather complex, hope you get my idea. Because I return the string like "8$True" or "02$False", so I use the IndexOf() function to get the position of letter "$", then use Substring() function to cut up the first part for Text value, and second part for Enabled attribute.

Again, I want to thanks to everyone who help me on my topic.
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer