|
No actually I have to use viewstate as I dont have to display the data into datagrid but may need to modify the data.Then Tracing the record into the hidden textbox will be very difficult.
So please help me with Viewstate.
Thanks and Regards.
|
|
|
|
|
Ok then Apurba's idea is good.But keep the datatable to a session varible.Why are u using viewstate?Hope it will solve your problem.
Tirthadip
|
|
|
|
|
Hi,
I respect your idea and Apurba's but actually problem with the session is that I will have to distore session when I exit that form so I dont want to use.
I have never used Viewstate so I want some help/code which stores all the texbox and listbox values in viewstate and how can I retrival the data from viewstate.
Thanks and regards.
varshavmane
|
|
|
|
|
Hi,
Thats not a problem you can use viewstate to store the datatable.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
Thanks for the reply.But can u please tell me the syntax of storing the datatable in viewstate.As when I dont use viewstate my datatable gets refresh and because of which I lose the pervious record.
Also how to retrive the values from viewstate for datatable.
I have not used viewstate so I need to try this.
Thanks and regards.
|
|
|
|
|
Hi,
It is quite simple. To put into viewstate you can use:
ViewState["daa"]=ds;
and to retrieve you can use:
DataSet s = new DataSet();<br />
s = (DataSet)ViewState["daa"];<br />
Response.Write(s.Tables[0].Rows[0][0].ToString());
Although here i have used dataset, same way you can use for datatable.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
I can do this for textbox and listbox values also???And if I use datatable then will how do I bind it with datagrid???
Thanks and Regards.
|
|
|
|
|
what i told is that first you create a datatable with all the columns which you require and then when you click add new button add a row to that datatable. And you can bind the datagrid with the datatable directly i.e dg.datasourse = datatable.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Fllowing is the code what I have used:
private void ibtnAdd_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Classes.CChecklist cchecklist = new Classes.CChecklist();
dgChecklist.AutoGenerateColumns = true;
DataTable dt = new DataTable("CheckList");
int cnt;
if(lbISOClauseNo.Items.Count > 0 && lbISODesc.Items.Count > 0 && txtExpected.Text != "" && txtTimeAllocated.Text != "")
{
for(cnt = 0 ; cnt < lbISOClauseNo.Items.Count ; cnt++)
{
if(cnt == lbISOClauseNo.Items.Count -1)
{
htxtFISOClauseNo.Value += lbISOClauseNo.Items[cnt].Value;
htxtFISOClauseDesc.Value += lbISODesc.Items[cnt].Value;
}
else
{
htxtFISOClauseNo.Value += lbISOClauseNo.Items[cnt].Value + "," ;
htxtFISOClauseDesc.Value += lbISODesc.Items[cnt].Value + "," ;
}
}
htxtFExpected.Value = txtExpected.Text;
htxtFTimePlanned.Value = txtTimeAllocated.Text;
cnt = Int32.Parse(htxtFChecklistNo.Value);
cnt++;
htxtFChecklistNo.Value = cnt.ToString();
}
//Checklist No
DataColumn dc = new DataColumn();
dc = dt.Columns.Add("Checklist No",System.Type.GetType("System.Int32"));
dc.Caption = "checklist_no";
//ISO Clause No
dc = dt.Columns.Add("ISO Clause No",System.Type.GetType("System.String"));
dc.Caption = "checklist_isoclause";
//Activities
dc = dt.Columns.Add("Activities",System.Type.GetType("System.String"));
dc.Caption = "checklist_activities";
//Expected Evidence
dc = dt.Columns.Add("Expected",System.Type.GetType("System.String"));
dc.Caption = "checklist_expected";
//Time Planned
dc = dt.Columns.Add("Time Allocated",System.Type.GetType("System.String"));
dc.Caption = "checklist_timeplanned";
DataRow dr = dt.NewRow();
dr["Checklist No"] = htxtFChecklistNo.Value;
dr["ISO Clause No"] = htxtFISOClauseNo.Value;
dr["Activities"] = htxtFISOClauseDesc.Value;
dr["Expected"] = htxtFExpected.Value;
dr["Time Allocated"] = htxtFTimePlanned.Value;
dt.Rows.Add(dr);
//Bind Datatable with DataGrid
dgChecklist.DataSource = dt;
dgChecklist.DataBind();
//Clear all the textbox and listbox.
lbISOClauseNo.Items.Clear();
lbISODesc.Items.Clear();
txtExpected.Text = "";
txtTimeAllocated.Text = "";
htxtFExpected.Value = "";
htxtFISOClauseDesc.Value = "";
htxtFISOClauseNo.Value = "";
htxtFTimePlanned.Value = "";
}
Whenever I click on add button datatable gets created again and I lose my last record.So I am in problem.
Please tell me how do I handle this
|
|
|
|
|
what you do is when the add button is clicked then you check whether you are having the datatable in the viewstate. If yes then use that(datatable in viewstate) to add the new record and if the datatable is not present in the viewstate(it will happen when the add button is clicked for the first time) then create a new datatable and put it into the viewstate. Finally attach that datatable which is there in viewstate to the datagrid.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
But how do I check whether datatable is created or not???
Thanks and Regards.
|
|
|
|
|
you can check like this
if(ViewState["daa"]!=null)
{
//Datatable is available in viewstate.
}
else
{
//Not available.
}
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
As u said I made the changes in the code but its giving compile time error saying "The name 'dt' does not exist in the class or namespace".I am copied the below:
private void ibtnAdd_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Classes.CChecklist cchecklist = new Classes.CChecklist();
dgChecklist.AutoGenerateColumns = true;
int cnt;
if(lbISOClauseNo.Items.Count > 0 && lbISODesc.Items.Count > 0 && txtExpected.Text != "" && txtTimeAllocated.Text != "")
{
for(cnt = 0 ; cnt < lbISOClauseNo.Items.Count ; cnt++)
{
if(cnt == lbISOClauseNo.Items.Count -1)
{
htxtFISOClauseNo.Value += lbISOClauseNo.Items[cnt].Value;
htxtFISOClauseDesc.Value += lbISODesc.Items[cnt].Value;
}
else
{
htxtFISOClauseNo.Value += lbISOClauseNo.Items[cnt].Value + "," ;
htxtFISOClauseDesc.Value += lbISODesc.Items[cnt].Value + "," ;
}
}
htxtFExpected.Value = txtExpected.Text;
htxtFTimePlanned.Value = txtTimeAllocated.Text;
cnt = Int32.Parse(htxtFChecklistNo.Value);
cnt++;
htxtFChecklistNo.Value = cnt.ToString();
}
if(ViewState["dtbl"]!=null)
{
//Datatable is available in viewstate.
DataRow dr = dt.NewRow();
dr["Checklist No"] = htxtFChecklistNo.Value;
dr["ISO Clause No"] = htxtFISOClauseNo.Value;
dr["Activities"] = htxtFISOClauseDesc.Value;
dr["Expected"] = htxtFExpected.Value;
dr["Time Allocated"] = htxtFTimePlanned.Value;
dt.Rows.Add(dr);
}
else
{
DataTable dt = new DataTable("CheckList");
//Checklist No
DataColumn dc = new DataColumn();
dc = dt.Columns.Add("Checklist No",System.Type.GetType("System.Int32"));
dc.Caption = "checklist_no";
//ISO Clause No
dc = dt.Columns.Add("ISO Clause No",System.Type.GetType("System.String"));
dc.Caption = "checklist_isoclause";
//Activities
dc = dt.Columns.Add("Activities",System.Type.GetType("System.String"));
dc.Caption = "checklist_activities";
//Expected Evidence
dc = dt.Columns.Add("Expected",System.Type.GetType("System.String"));
dc.Caption = "checklist_expected";
//Time Planned
dc = dt.Columns.Add("Time Allocated",System.Type.GetType("System.String"));
dc.Caption = "checklist_timeplanned";
ViewState["dtbl"] = dt;
DataRow dr = dt.NewRow();
dr["Checklist No"] = htxtFChecklistNo.Value;
dr["ISO Clause No"] = htxtFISOClauseNo.Value;
dr["Activities"] = htxtFISOClauseDesc.Value;
dr["Expected"] = htxtFExpected.Value;
dr["Time Allocated"] = htxtFTimePlanned.Value;
dt.Rows.Add(dr);
}
dgChecklist.DataSource = dt;
dgChecklist.DataBind();
}
Please help me...
Thanks and regards
|
|
|
|
|
Hi,
I have modified the code. You copy and paste this and check.
private void ibtnAdd_Click(object sender, System.Web.UI.ImageClickEventArgs e)<br />
{<br />
Classes.CChecklist cchecklist = new Classes.CChecklist();<br />
dgChecklist.AutoGenerateColumns = true;<br />
int cnt;<br />
if(lbISOClauseNo.Items.Count > 0 && lbISODesc.Items.Count > 0 && txtExpected.Text != "" && txtTimeAllocated.Text != "")<br />
{<br />
for(cnt = 0 ; cnt < lbISOClauseNo.Items.Count ; cnt++)<br />
{<br />
if(cnt == lbISOClauseNo.Items.Count -1)<br />
{<br />
htxtFISOClauseNo.Value += lbISOClauseNo.Items[cnt].Value;<br />
htxtFISOClauseDesc.Value += lbISODesc.Items[cnt].Value;<br />
}<br />
else<br />
{<br />
htxtFISOClauseNo.Value += lbISOClauseNo.Items[cnt].Value + "," ;<br />
htxtFISOClauseDesc.Value += lbISODesc.Items[cnt].Value + "," ;<br />
}<br />
}<br />
htxtFExpected.Value = txtExpected.Text;<br />
htxtFTimePlanned.Value = txtTimeAllocated.Text;<br />
cnt = Int32.Parse(htxtFChecklistNo.Value);<br />
cnt++;<br />
htxtFChecklistNo.Value = cnt.ToString();<br />
}<br />
if(ViewState["dtbl"]!=null)<br />
{<br />
DataRow dr = dt.NewRow();<br />
dr["Checklist No"] = htxtFChecklistNo.Value;<br />
dr["ISO Clause No"] = htxtFISOClauseNo.Value;<br />
dr["Activities"] = htxtFISOClauseDesc.Value;<br />
dr["Expected"] = htxtFExpected.Value;<br />
dr["Time Allocated"] = htxtFTimePlanned.Value;<br />
<br />
DataTable dt = (DataTable)ViewState["dtbl"];<br />
dt.Rows.Add(dr);<br />
ViewState["dtbl"] = dt;<br />
dgChecklist.DataSource = (DataTable)ViewState["dtbl"];<br />
dgChecklist.DataBind();<br />
}<br />
else<br />
{<br />
DataTable dt = new DataTable("CheckList");<br />
DataColumn dc = new DataColumn();<br />
dc = dt.Columns.Add("Checklist No",System.Type.GetType("System.Int32"));<br />
dc.Caption = "checklist_no";<br />
<br />
dc = dt.Columns.Add("ISO Clause No",System.Type.GetType("System.String"));<br />
dc.Caption = "checklist_isoclause";<br />
<br />
dc = dt.Columns.Add("Activities",System.Type.GetType("System.String"));<br />
dc.Caption = "checklist_activities";<br />
<br />
dc = dt.Columns.Add("Expected",System.Type.GetType("System.String"));<br />
dc.Caption = "checklist_expected";<br />
<br />
dc = dt.Columns.Add("Time Allocated",System.Type.GetType("System.String"));<br />
dc.Caption = "checklist_timeplanned";<br />
ViewState["dtbl"] = dt;<br />
<br />
DataRow dr = dt.NewRow();<br />
dr["Checklist No"] = htxtFChecklistNo.Value;<br />
dr["ISO Clause No"] = htxtFISOClauseNo.Value;<br />
dr["Activities"] = htxtFISOClauseDesc.Value;<br />
dr["Expected"] = htxtFExpected.Value;<br />
dr["Time Allocated"] = htxtFTimePlanned.Value;<br />
<br />
dt.Rows.Add(dr);<br />
<br />
dgChecklist.DataSource = dt;<br />
dgChecklist.DataBind();<br />
}
And see where you were doing wrong. : -D
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thanks a lot.Now its working.Thanks again.Bye
Regards,
Varsha.
|
|
|
|
|
always welcome.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi again,
Now can u please tell me how do I save that Datagrid into Database???
Thanks and regards,
Varsha
|
|
|
|
|
Hi,
You can send the records from front end as comma separated sting and then in your stored procedure you can separate it and store it into the database.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
Thanks for reply.Can't we directly fire a query in a loop where I pass the datatable to my Class file.I mean Y do we have to write a Stored Procedure.
Thanks and Regards
|
|
|
|
|
ya sure it can be done like that also. You can go through the records one by one(in a loop) and then execute a insert statement to insert the record in the database.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
Will it manage the transaction,I mean it may happen that some records are inserted and other didnt.Can we pass datatable to Insert function which is in class file or can we define property for this?What is ur suggestion on this???
Whatever your suggestion please give me the syntax for the same.
Thanks and Regards.
|
|
|
|
|
Hi,
Probably we can maintain the transactiob in the data access layer also. But that i have never used. But for the second option(stored procedure) we can maintain it easily.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Sorry to say I have not used any of the methods as I dont know much about Stored Procedure and the layer which u are saying that also I dont know.
Thanks and Regards.
|
|
|
|
|
I have discused this on another forum also. url for the same discussion is :
http://www.codingforums.com/showthread.php?t=88711
anybody have any idea regarding recordset file (save method of ado) using asp.net ??
|
|
|
|
|
I am using ASP.net 1.1 in Visual Studio 2003. I have a datagrid that changes a rows color based on a column's value. I want the links to change to the same ForeColor as the text in the bound columns. Here is some of my code:
VB CODE
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
SqlDataAdapter1.Fill(DataSet11, "Table")
DataGrid1.DataSource = DataSet11.Tables("Table").DefaultView
DataGrid1.DataBind()
SqlDataAdapter2.Fill(DsBackLogHrs1, "dbo_USER_BackLog_Hours")
txtBackLogHrs.DataBind()
End Sub
Private Sub dgContacts_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
' Make sure that this is a data row and not a header or footer.
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
' Get the value of the SortOrder Field. This field is an integer that describes the Data row.
' 0 = active Ro
' 5 = Parts Are In (Active RO)
' 10 = Parts Are In (Non Active RO)
' 30 = Comeback
' 50 = Customer Waiting (Non active RO)
' 300 = Stale RO (No one has punched onto this RO for 48 hours)
' 150 = Open RO
' 175 = Parts on BackOrder
Dim isTimeAvail As Single
Dim isTimetoPickup As Single
Dim isTimetoNewPickup As Single
Dim isNewPickup As DateTime
Dim isDescript As String = CType(DataBinder.Eval(e.Item.DataItem, "Descript"), String)
Dim isDateProm As DateTime = CType(DataBinder.Eval(e.Item.DataItem, "DateProm"), DateTime)
Dim isSortOrder As Single = CType(DataBinder.Eval(e.Item.DataItem, "SortOrder"), Single)
Dim isFlatHrs As Single = CType(DataBinder.Eval(e.Item.DataItem, "FlatHrs"), Single)
Dim isTechHrs As Single = CType(DataBinder.Eval(e.Item.DataItem, "TechHrs"), Single)
Select Case isSortOrder
Case 5
e.Item.ForeColor = System.Drawing.Color.Green
e.Item.Font.Bold = System.Drawing.FontStyle.Bold
Case 10
e.Item.BackColor = System.Drawing.Color.Green
e.Item.ForeColor = System.Drawing.Color.White
Case 30
e.Item.ForeColor = System.Drawing.Color.DarkRed
e.Item.Font.Bold = System.Drawing.FontStyle.Bold
Case 50
e.Item.ForeColor = System.Drawing.Color.Navy
e.Item.Font.Bold = System.Drawing.FontStyle.Bold
Case 175
e.Item.BackColor = System.Drawing.Color.Gray
Case 300
e.Item.BackColor = System.Drawing.Color.Tan
e.Item.ForeColor = System.Drawing.Color.Black
End Select
ASP Code:
<title>WebForm1
.inGreen {COLOR: green; TEXT-DECORATION: none}
.inDarkRed {COLOR: DarkRed; TEXT-DECORATION: none}
.inNavy {COLOR: Navy; TEXT-DECORATION: none}
.inBlack {Color: Black; Text-decoration: None}
.inOrange {Color: OrangeRed; Text-decoration: None}
.inWhite {Color: White; Text-decoration: None}
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 80px" runat="server" height="383px" width="990px" datasource="<%# DataSet11 %>" autogeneratecolumns="False" datamember="Table" bordercolor="Fuchsia">
<itemstyle font-names="Verdana">
<columns>
<asp:hyperlinkcolumn datatextfield="SalesId" datanavigateurlfield="SalesId" datanavigateurlformatstring="javascript:varwin=window.open('WebForm2.aspx?SalesId={0}',null,'width=950,height=625, resizable=yes, Scrollbars=yes');void('');"
="" headertext="Repair Order #">
<headerstyle font-names="Verdana" font-bold="True">
<asp:hyperlinkcolumn datatextfield="CustName" datanavigateurlfield="SalesId" datanavigateurlformatstring="javascript:varwin=window.open('CustomerInfo.aspx?SalesId={0}',null,'width=892,height=350, resizable=yes, Scrollbars=yes');void('');"
="" headertext="Customer Name">
<headerstyle font-names="Verdana" font-bold="True">
<itemstyle font-names="Verdana">
<asp:boundcolumn datafield="DateCreated" headertext="Date Create" dataformatstring="{0 }">
<headerstyle font-names="Verdana" font-bold="True">
<asp:boundcolumn datafield="DateProm" headertext="Date/Time Promised">
<headerstyle font-names="Verdana" font-bold="True">
<itemstyle font-size="Smaller" font-names="Verdana">
<asp:boundcolumn visible="False" datafield="SortOrder" headertext="SortOrder">
<asp:boundcolumn datafield="Descript" headertext="Description">
<headerstyle font-names="Verdana" font-bold="True">
<asp:boundcolumn datafield="FlatHrs" sortexpression="FlatHrs" headertext="FlatHrs">
<asp:hyperlinkcolumn datatextfield="TechHrs" datanavigateurlfield="SalesId" datanavigateurlformatstring="javascript:varwin=window.open('TechPunches.aspx?SalesId={0}',null,'width=950,height=625, resizable=yes, Scrollbars=yes');void('');"
="" headertext="TechHrs" datatextformatstring="{0:N2}">
<cc1:webtimer id="WebTimer1" runat="server" <="" small="">
Thanks for all the help
NewbieDave
|
|
|
|