|
Well, writing the above code in page load doesn't make sense. When the page loads first time, SelectedRow will be NULL . Is this throwing error when you use it in the selected index changed event?
|
|
|
|
|
Well I hope I am not the only one who has ever done this, I have faith that I am not.
But, I thought about just what you replied Navaneeth, and realized the code in the page_load didn't make sense. So I removed it but the SelectedIndexChanged event never fired. So I (just now) reviewed the event. I works now because I put the code in the GridView1 event as opposed to the "GridView2" event.
Thanks for your reply and I shall bow out humbly now...
|
|
|
|
|
At the time when the page gets loaded, do you think that the GridView1 has any selected row? The problem lies here.
There is no foolish question, there is no final answer...
|
|
|
|
|
ffowler wrote: In the Page_Load and SelectedIndexChanged event I simply have
'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();'
The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview.
Check Selected Row index for null before the statement.
|
|
|
|
|
Hi,
I have table inside server controls like Text box and dropdown, i want to clear all controls inside the Table, instead of giving all controls name. i want to use the Table name only. if any one knows plz reply me..
thanks...
|
|
|
|
|
Your question is quite ambiguous to me. What do you mean by clearing all controls? Do you want to remove all controls that are placed inside the tables?
There is no foolish question, there is no final answer...
|
|
|
|
|
ok i will clearly explain,
inside table three rows having 3 text boxes. i want to clear the values on the text box from javascript. instead of taking 3 text box client can i take table clientid,
Ex:
document.getelementid("<%= textbox1.ClientID%>").value==""; this is obviously normal way to clear.
my intension is , i want to use the table id to calear all text of controls inside the table.
i hope now u will understand my problem
..
|
|
|
|
|
kanadoss wrote: document.getelementid("<%= textbox1.ClientID%>").value==""; this is obviously normal way to clear.
No.
kanadoss wrote: my intension is , i want to use the table id to calear all text of controls inside the table.
Get the tables object
var tableObj = document.getelementid("<%= textbox1.ClientID%>")
Use getElementsByTagName to get all the input controls. Something like
var controls = tableObj.getElementsByTagName("input")
controls variable will have all the input objects under that table. Now iterate over the elements and set it's value. BTW, why do you want to do this using only the table id when you can use the text box id directly. I guess that will be more reliable.
|
|
|
|
|
Oh yeah, it is quite clear now. I think, what would you intend to do is not really possible? It doesn't matter whether controls are parent or child; their control id at the render time always differ and those are unique. So I don't think that it is possible to set properties of child controls by using parent control. But you can iterate through the control collections by running a loop and check if control name starts with the parent control name then set its value to empty. But you have to validate also.
There is no foolish question, there is no final answer...
|
|
|
|
|
Can any one help me
How to create server control at run time in ASP.Net 2.0
|
|
|
|
|
|
Amit Patel1985 wrote: How to create server control at run time in ASP.Net 2.0
Which control you want to create ? Create the object of that control class, set the properties and add them to the page.
Be careful when you creating control at runtime. You should take care of view state of the control and its depends in which event you are creating them.
|
|
|
|
|
Hi,
I have to generate a word document dynamically in .Net.
I have to write the contents of the GridView to the Word document.
I am able to do all but,the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box.
Can anyone please tell me that how to store the word file automatically to a particular location?
I have given the code below.
string attachment = "attachment; filename=" + strFilePath;
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-word";
StringWriter sWriter = new StringWriter();
HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter);
gvRCA.RenderControl(htwWriter);
Response.Write(sWriter.ToString());
Response.End();
Yazhini
|
|
|
|
|
YazhiniP wrote: the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box.
You should never tell the client yes, unless you know enough about what you're doing, to know that it's possible. In this case, it's not possible. Imagine if it was, if every website could just put files into your file system without asking you first.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
ok...I dropped the idea of using Response object.I tried using FileStream and StreamWriter.but,how to pass the GridView object to the StreamWriter?
FileStream fs = File.Create(path);
fs.Close();
StreamWriter sw = new StreamWriter(path);
StringWriter sWriter = new StringWriter();
HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter);
gvRCA.RenderControl(htwWriter);
sw.Write(htwWriter);
sw.Close();
The above code writes only System.Web.UI.HtmlTextWriter to the word file.
I am beginner in .Net and i dont know a lot.
Do u have any idea on how to do this?.
Thanks in advance...
Yazhini
|
|
|
|
|
Dim img As FileUpload = CType(imgUpload, FileUpload)
Dim imgByte As Byte() = Nothing
Dim imgtype As String = Nothing
If img.HasFile AndAlso Not img.PostedFile Is Nothing Then
'To create a PostedFile
Dim File As HttpPostedFile = imgUpload.PostedFile
'Create byte Array with file len
imgByte = New Byte(File.ContentLength - 1) {}
imgtype = New String(File.ContentType)
'force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength)
End If
' Insert the employee name and image into db
c.Open()
Dim sql As String = "INSERT INTO tblImg (img_type, img_stream)VALUES (@img_type,@img_stream) "
Dim cmd As SqlCommand = New SqlCommand(sql, c)
cmd.Parameters.AddWithValue("@img_type", imgtype)
cmd.Parameters.AddWithValue("img_stream", imgByte)
Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())
lblResult.Text = String.Format("Employee ID is {0}", id)
|
|
|
|
|
jigneshp25 wrote: cmd.Parameters.AddWithValue("@img_type", imgtype)
cmd.Parameters.AddWithValue("img_stream", imgByte)
What do you notice about the two parameters you're pasing in ? Yes, one has an @ and the other does not. Hence the problem.
It pays to read the error message and then assume that it's true.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
jigneshp25 wrote: cmd.Parameters.AddWithValue("@img_type", imgtype)
cmd.Parameters.AddWithValue("img_stream", imgByte)
where is @ for the img_stream ? When your debugger showing the error , then click on the error, debugger redirect you to the correct line.
|
|
|
|
|
Hello........I m decveloping an application in which i hav to create data table dynamically......i hav written the code the but getting the error....plz help me...code is below:-
Dim objDT As New System.Data.DataTable
Dim objDR As System.Data.DataRow
Private Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
If Not IsPostBack Then
makeCart()
End If
End Sub
Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))
Session("Cart") = objDT
End Function
Sub Delete_Item(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
objDT = Session("Cart")
objDT.Rows(e.Item.ItemIndex).Delete()
Session("Cart") = objDT
dg.DataSource = objDT
dg.DataBind()
lblTotal.Text = "$" & GetItemTotal()
End Sub
Sub AddToCart(ByVal s As Object, ByVal e As EventArgs)
objDT = Session("Cart")
Dim Product = ddlProducts.SelectedItem.Text
objDR = objDT.NewRow(GETTING ERROR IN THIS LINE)
'Error is same which is written in Subject line
objDR("Quantity") = txtQuantity.Text
objDR("Product") = ddlProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
objDT.Rows.Add(objDR)
Session("Cart") = objDT
dg.DataSource = objDT
dg.DataBind()
Dim blnMatch As Boolean = False
For Each Me.objDR In objDT.Rows
If objDR("Product") = Product Then
objDR("Quantity") += txtQuantity.Text
blnMatch = True
Exit For
End If
Next
If Not blnMatch Then
objDR = objDT.NewRow
objDR("Quantity") = Int32.Parse(txtQuantity.Text)
objDR("Product") = ddlProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
objDT.Rows.Add(objDR)
End If
lblTotal.Text = "$" & GetItemTotal()
End Sub
Function GetItemTotal() As Decimal
Dim intCounter As Integer
Dim decRunningTotal As Decimal
For intCounter = 0 To objDT.Rows.Count - -1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("Cost") * objDR("Quantity"))
Next
Return decRunningTotal
End Function
</script>
|
|
|
|
|
I suspect that objDT is null. Have you stepped through the code, to see if this is so ? How about writing code that checks for nulls and doesn't blow up ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Why don't use "Session("Cart")" variable which already stored the data table. objDT is returning null. Typecast the session variable into a datatable object.
There is no foolish question, there is no final answer...
|
|
|
|
|
ankurdsharma wrote: objDT = New System.Data.DataTable("Cart")
ankurdsharma wrote: objDT = Session("Cart")
Did you check the Session variable for null ?
Where is the Type Cast ?
ankurdsharma wrote: objDR = objDT.NewRow(GETTING ERROR IN THIS LINE)
'Error is same which is written in Subject line
So that the reason that you are getting error here.
|
|
|
|
|
How to Add the BindingManager to the tool box in asp.net
modified on Friday, June 12, 2009 7:21 AM
|
|
|
|
|
Hi Everybody
I need to fetch most visited articles from my News module...Please give me some idea
Thanks in advance
Ramkumar
|
|
|
|
|
What have you tried ? What seems the obvious way to do that ? Do you store a counter for how often a page is visited ? If not, how do you expect to do this ? If so, it suddenly becomes trivial, right ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|