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(Containe r, "DataItem.Day01")].Split(" $")}[0]
%>'
Enabled='<%#
{[DataBinder.Eval(Containe r, "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
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,
...
<asp:TextBox id=txtDay1 Text='<%# DataBinder.Eval(Container,
| 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,
DataBinder.Eval(Container,
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(Containe
%>'
Enabled='<%#
{[DataBinder.Eval(Containe
%>' >
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
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(DataBinde r.Eval(Con tainer, "DataItem.Day01")).IndexOf ("$")+1)
) %>'
Text='<%# Convert.ToString(
DataBinder.Eval(Container, "DataItem.Day01")
).Substring(
0,Convert.ToString(DataBin der.Eval(C ontainer, "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.
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,
).Substring(
Convert.ToString(DataBinde
) %>'
Text='<%# Convert.ToString(
DataBinder.Eval(Container,
).Substring(
0,Convert.ToString(DataBin
%>' 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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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