|
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
|
|
|
|
|
I guess you create css classes for the hyperlink column, the sample can be found from here[^]:
|
|
|
|
|
I recently discovered so much can be done by using xml and xslt transformation. But i wanted which would be more efficient desiging pages using xml and xml transformation or using datagrid and other control while displaying data
leo
Kathmandu, Nepal
|
|
|
|
|
Depends on your requirements.
If you want someone, who has no idea about datogrid to be able to transform your HTMl, use xsl.
Datagrid is more powerful, much easier to do sorting and paging for example.
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
|
|
|
|
|
I also posted this message at the C# forum as I am programming in that so if this post looks familiar....
I have a project where the user enters a part number. Based on that part number a datagrid will return associated info. The main row will return 1-to-1 items such as part description, drawing location, etc. I plan to use nested datagrids as there will be multiple subparts per part, multiple costs per part etc.
Anyhow, all total I have about 11 tables I need to use. The problem I am facing is that not all parts have a drawing location. When this is blank, the entire row turns up blank.
How do I fix it so that the grid returns any data that is present, and ignores null information?
Here is the C# code:
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Web;<br />
using System.Web.SessionState;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.HtmlControls;<br />
using System.Data.SqlClient;<br />
using System.Configuration;<br />
<br />
namespace WebBasedPartsDB<br />
{<br />
public class WebForm2 : System.Web.UI.Page<br />
{<br />
protected System.Web.UI.WebControls.TextBox txtSearchPart2;<br />
protected System.Web.UI.WebControls.DataGrid DataGrid2;<br />
protected System.Web.UI.WebControls.Button btnSearch2;<br />
protected string strPartNumberInput2;<br />
<br />
public String strConnectSQL = (ConfigurationSettings.AppSettings["ConnectionString"]);<br />
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
}<br />
<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.btnSearch2.Click += new System.EventHandler(this.btnSearch2_Click);<br />
this.DataGrid2.SelectedIndexChanged += new System.EventHandler(this.DataGrid2_SelectedIndexChanged);<br />
this.Load += new System.EventHandler(this.Page_Load);<br />
<br />
}<br />
#endregion<br />
<br />
private void btnSearch2_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInput2 = txtSearchPart2.Text;<br />
string SQLString = "SELECT c.cost, c.costtypeid, ct.description, pt.description as ptDescription FROM costs c INNER JOIN Parts p ON c.PartID = p.Id INNER JOIN PartTypes pt on pt.ID = p.PartTypeID INNER JOIN CostTypes ct on ct.ID = c.costtypeid WHERE p.PartNumber = @PartID";<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", strPartNumberInput2);<br />
BindGrid(cmd, DataGrid2);<br />
}<br />
<br />
<br />
private void BindGrid (SqlCommand command, System.Web.UI.WebControls.DataGrid DGrid)<br />
{<br />
SqlDataAdapter adapter = new SqlDataAdapter(command);<br />
DataSet ds = new DataSet();<br />
adapter.Fill(ds);<br />
DGrid.DataSource = ds;<br />
DGrid.DataBind();<br />
<br />
}<br />
<br />
private void DataGrid2_SelectedIndexChanged(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
<br />
}<br />
}
|
|
|
|
|
Change INNER JOIN DraftingData
to Left Join DraftingData
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
D'oh! This is what happens when you don't program for a couple years!!! I have forgotten all the simple things!
|
|
|
|
|