Forms Data Controls :: Row Data Bound Method That Inserts A Row When Comparing Values On A Particular Field
Jan 22, 2010
I have a gridview, which on the row data bound method that inserts a row when comparing values on a particular field. If the two values are different, a new row is inserted, if not no row is inserted. This coding is working as a grouping gridview, and is working correctly. However, I have problem, and problem is counting the rows between each group, which I want to display in my blank row between each group, the value of which I am holding in a hiddenfield.
When I try to do it, the first group doesn't show the result, but is displayed on the next group. I am pretty sure that I am doing something wrong. My approach is that if the value between the last row and the existing row are different, then the value is one, on the next row data bound event, if the values are the same then the value is increased by one, else the value is one because it is a new group. Here is my code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Table tbl = e.Row.Parent as Table;
TableCell cell = new TableCell();
CheckBox chk = new CheckBox();
Label lbl2 = new Label();
HiddenField rowValue = new HiddenField();
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Visible = false;
}
else
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Session["count"] = 1;
Label lbl = (Label)e.Row.FindControl("lblValue");
string str1 = ((Label)(lbl)).Text;
string prevStr= (string)Session["previousStr"];
if (prevStr== str1)
{
lbl.Visible = false;...................
I am dealing with dynamic fields in a for loop and now I need to retrieve the values that are being typed in the dynamic fields, any idea how can I do that? 2)also when I click the submit button, upon postback, the dynamic fields have gone missing, have been trying to slove that, but i did not, anyone knows how to deal with this? kinda urgent :x
3) and How do you compare the 2 dynamic fields? For eg: Im comparing the tbSch[i] to tbSch[i], so that the dates cannot be the same, am using a compare validator, but it throws me error that im comparing the same fields :) even though i change to ("tbSch" + i) for both, sorry Will provide my code snippet as follow :D tbNum is a textbox where user enter numbers and click generate
protected void btnGen_Click(object sender, EventArgs e) { for (int i = 0; i < Convert.ToInt32(tbNum.Text); i++) { // label and textbox needed Label lblSch = new Label(); TextBox tbSch = new TextBox(); Label lblWsGrp = new Label(); DropDownList ddlWsGrp = new DropDownList(); CompareValidator cvSame = new CompareValidator(); cvSame.ID = "cvSame" + i; cvSame.ErrorMessage = "Date cannot be the same"; cvSame.Operator = ValidationCompareOperator.NotEqual; cvSame.Type = ValidationDataType.Date; cvSame.Display = ValidatorDisplay.Dynamic; cvSame.EnableViewState = true; cvSame.ControlToValidate = (tbSch.ID);<<<<< what should be the value in here? cvSame.ControlToCompare = (tbSch.ID);<<<<<<<<<< and here? //schdule date lblSch.ID = "lblSch" + i; lblSch.Text = "Session Date : "; lblSch.EnableViewState = true; tbSch.ID = "tbSch" + i; tbSch.Width = 210; tbSch.Height = 27; tbSch.EnableViewState = true; //workshop grp lblWsGrp.ID = "lblwsgrp" + i; lblWsGrp.Text = "Workshop Group : "; lblWsGrp.EnableViewState = true; ddlWsGrp.ID = "ddlWsGrp" + i; ddlWsGrp.Height = 27; ddlWsGrp.Width = 210; ddlWsGrp.EnableViewState = true; ddlWsGrp.Items.Add("1"); ddlWsGrp.Items.Add("2"); //table to store data TableRow trow = new TableRow(); TableRow trow2 = new TableRow(); //row1 TableCell tc1 = new TableCell(); TableCell tc2 = new TableCell(); TableCell tc3 = new TableCell(); TableCell tc4 = new TableCell(); //row2 TableCell tc5 = new TableCell(); TableCell tc6 = new TableCell(); TableCell tc7 = new TableCell(); TableCell tc8 = new TableCell(); TableCelltc9 = new TableCell(); tc1.Controls.Add(lblSch); tc2.Controls.Add(tbSch); tc3.Controls.Add(lblWsGrp); tc4.Controls.Add(ddlWsGrp); tc5.Controls.Add(space); tc6.Controls.Add(CeSess); tc7.Controls.Add(space); tc8.Controls.Add(space); tc9.Controls.Add(cvSame) trow.Cells.Add(tc1); trow.Cells.Add(tc2); trow.Cells.Add(tc3); trow.Cells.Add(tc4); trow2.Cells.Add(tc5); trow2.Cells.Add(tc6); trow2.Cells.Add(tc7); trow2.Cells.Add(tc8); trow2.Cells.Add(t9); this.table3.Rows.Add(trow); this.table3.Rows.Add(trow2); } }
I have a form that contains a text box called "MyDate" in which the user enters a date. I have a table that contains records of which one of the fields in the record is a date field named "DateAvailable" (type is "datetime"). I want to compare the data in the text box to the "DateAvailable" field in record. How do I define my text box as a "datetime" field.
I want to add boundfield to the Detailsview control at the run time. The data is coming from the dataset, which is fetching data from SqlDataAdapter. I tried using the following code
string st = "select * from tbrob,tbemp,tbcty,tbcmp where robfircod=" + TextBox1.Text.ToString() + " and robempcod=empcod and robctycod=ctycod and robcmpcod=cmpcod";
How do I bound a Label to a datasource and its field?I got set up the datasource to a gridview, but don't know how to bind a label to the same datasource.
eI am using themes to set the Gridview font size and font name. I need to set the boundfield to the same font and size as I want it to be application to all the columns in gridview. How can I specify the boundfield properties in the themes.
I am listing details using a gridview and wish to just display the first 50 characters of a 1000 character field. I feel this should be simple but cannot find the solution.
I'm hitting a wall trying to format a boundfield of a gridview. I've tried suggestion about setting the htmlencode to false, but that didn't make a difference.The column I am trying to format is:<asp:BoundField DataField="FromDate" HeaderText="Start Date" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False" />
I have a date/time stored in a smalldatetime field (ms sql 2005) that i want to compare with the current time and receive a difference. If the difference is less than 30 minutes, do this....if more do that....
I have a grid that is built as well as populated dynamically through c# code. The grid has 3 columns(3 bound fields). And data is being populated in those bound fields through c# code programatically.
Elaborating my question: I have 3 bound field columns(col1, col2 & col3) . I have to increase the rowspan of col2 and col3 headertext's to 2 i.e I want the col2 and col3 header texts to span across two row cells. But the col1 header text should span across just 1 row. And the extra rowscell that is created under col1 due to the increase in the rowspans (of col2 and col3 boundfield headertexts) should be populated with some random text, i.e something like XXXXX
i am implementing a update query module.i am displaying all fields from a table for a term searched. well now i am implementing update option for the record which are displayed, i have like 70 columns in my table, and i want to know how to restrict some selected fields to be only read only while the form can be updated ?Like if user select to update a record then some selected field such as "Timestamp, UID etc some selected fields" remains READ ONLY !
I have a GridView with an image button in a TemplateField in the last column.
I would like to pass the GridView row values (Bound Field Values - a record) to a JavaScript function to create another html table of selected records in ClientSide (like jCart-A shopping cart).
I would like to know how to pass all GridView column values to the javascript when the image at the end of the respective row is clicked.
I am using VS 2008 SP1. My also have included CSS Friendly adapter [URL] in my project ( I mentioned this because my GridView Empty data template is not showing when using GridView's CCS Friendly adapter). I have a GridView and a DetailsView. When a record in GridView is selected its details information is shown in the Details View. Type of Data source I am using is ObjectDataSource. My Insert and Update methods works perfectly. It is only the Delete method that is passing null values to the underlying object delete method. My source codes for both the UI, BLL, DAL is shown below
I have been struggling for a while 72 hours with this .When I update the form view a NULL value is inserted in my product ID field instead of the productID from the drop down list.
i have data bound field named "Address" haveing width "100px" . whenever i put the string like "6666666666666666666666666" then structure of grid is disturbed even i have set the ItemStyle_wrap="false". but when i put the string like "666 666 6666666 6666666666 666666666" the structure of grid does not change.
when I click on "update" button of my detailsview I have the same values on my db table.It seems that the update method don't get my new values inserted in the "boundields" in editing mode.Below there is my code.
What is the best way to pass Values from one page to another in ASP.NET(C#)I am using a GRID and has EDIT column in it. So when user clicks on the Edit link the values of the row that has been clicked is passed onto another page (Edit form).Which is best way to pass values, considering some data may be sensitive User data.