|
How do can one specify the datakeynames when i have more than one parameter to be passed to a datagrid source?
t.aransiola
|
|
|
|
|
in code behind:
GridView1.DataKeyNames="Key1,Key2,Key3";
in source:
<asp:GridView runat="server" id="GridView1" DataKeyNames="Key1,Key2,Key3" />
hth,
~dnc
|
|
|
|
|
Probably a simple question.
I have a form with a search button. The click event of the button calls a method for preforming a search. The search method returns a collection of business objects which I bind to a DataList.
The binding only appears to work properly when done in the OnInit event. That's fine.
The issue is in the order of the events. When the user clicks the search button the buttons click event isn't fired until after the init event.
<br />
protected void btnSearch_Click(object sender, EventArgs e)<br />
{<br />
List<Customers> customersList = Search();<br />
<br />
}<br />
I need to trigger a second post back to get the OnInit to fire again. Or do I?
-Mike.
|
|
|
|
|
Doing ASP.NET for several years, I never needed to handle OnInit() . Is there a reason you use it?
Usually my code looks something like this:
protected void Page_Load( object sender, EventArgs e )
{
if ( !IsPostBack )
{
List customersList = Search();
...
}
}
|
|
|
|
|
Reading the MSDN articles I was under the impression that dynamic content (in this case the template of my DataList has a custom control) needs to be created during the init event.
But, if you say you can do it through the Page_Load I believe ya. However, so far that has not worked.
This is what I have now tried:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (SearchResults != null)
{
SearchResultsList.DataSource = SearchResults;
SearchResultsList.DataBind();
}
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
SearchResults = Search();
}
private List<Customer> SearchResults
{
get
{
return Session["SearchResults"] as List<Customer>;
}
set
{
Session["SearchResults"] = value;
}
}
When I hit search, nothing shows up. It doesn't appear as though the bind is ever happening.
It's probably something obvious. Usually is the case.
-Mike.
|
|
|
|
|
I guess you need to do something like this:
protected void btnSearch_Click(object sender, EventArgs e)
{
SearchResults = Search();
SearchResultsList.DataSource = SearchResults;
SearchResultsList.DataBind();
}
|
|
|
|
|
That got it!
I was actually already doing this when I first started, but nothing was showing up. Turns out the problem wasn't the order of where I set my DataSource but rather where I render my HTML in my custom control (the one in the template of the DataList).
Thanks for your help.
-Mike.
|
|
|
|
|
Dear All,
I bound my tree view to a sitemap datasourec from the web.sitemap
my propblem is that i want to display a confirmation message (javascript) when the node is clicked because clicking it does much on the database so i want to make sure that the client confirms clicking before doin that
I would appreciate any comment or hint
Thank in advance
Best Regards
3ala2
|
|
|
|
|
Hi
I am using ASP.Net 1.1.
I just want to get idea about AJAX with ASP.Net 1.1
Say for example, I have tmp.aspx which contain one textbox, a button and one lable. Now i want to print address from database on base of textbox value on click of button without server trip with AJAX. I have a function "GetAddress(String name)" in tmp.cs. So could anybody direct me how can i call this function using AJAX on click of button to save round trip.
Actully I have tried by assigning label using XMLHttpRequestobj.responsetext but whole response is coming. i just want to excute one function on button click thats it. Please direct me.
Actully this is not my actual requirnment but if i get this solution then i can handle any requirnment about AJAX.
Thanks in Advance to that genius who will make me clear about AJAX.
Thanks
Anand
|
|
|
|
|
There are a number of libraries that can make this easier for you. Try this one
http://www.ajaxpro.info/[^], it has examples that should be helpful to you.
only two letters away from being an asset
|
|
|
|
|
AJAX in Action published by Manning is a great book.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a database in which I store the items that a customer added to the shoppingcart. Now I try to get the data and put it into the shoppingcart when the user loggs back in and there were items he didn't purchased yet but left in cart last time he was logged.
It will display the right quantity of each product, but it shows the Name and price of last recieved product in my ShoppingCart display on all products.
Here is code I have so far for getting items from DB and adding to ShoppingCart:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Membership.GetUser() Is Nothing Then
StoreManager.ShoppingCart.UserID = Membership.GetUser().UserName
If Not Session("Logged") Then
StoreDB.GetShoppingCart(Membership.GetUser().UserName)
Session("Logged") = True
End If
Else
HttpContext.Current.Session("ShoppingCart") = New ShoppingCart()
StoreManager.ShoppingCart.UserID = ""
Session("Logged") = False
End If
End Sub
Public Shared Sub GetShoppingCart(ByVal userID As String)
Try
Using myCon As New SqlConnection(AppConnection.ConnectionString)
Dim myCom As SqlCommand = New SqlCommand("sprocGetShoppingCartItems", myCon)
myCom.CommandType = CommandType.StoredProcedure
myCom.Parameters.AddWithValue("@cartID", userID)
Dim prod As Product = New Product
Dim qty As Integer = 0
myCon.Open()
Using myRd As SqlDataReader = myCom.ExecuteReader(CommandBehavior.CloseConnection)
While myRd.Read()
prod.CategorieID = myRd.GetInt32(myRd.GetOrdinal("CategorieID"))
prod.ProductID = myRd.GetInt32(myRd.GetOrdinal("ProductID"))
prod.ProductName = myRd.GetString(myRd.GetOrdinal("ProductName"))
prod.ProductPrice = myRd.GetDecimal(myRd.GetOrdinal("ProductPrice"))
prod.ProductMini = myRd.GetString(myRd.GetOrdinal("ProductImage"))
prod.Qty = myRd.GetInt32(myRd.GetOrdinal("Quantity"))
MsgBox("Adding: " & prod.ProductName)
StoreManager.ShoppingCart.AddDB(prod, prod.Qty)
End While
myRd.Close()
End Using
End Using
Catch ex As Exception
' error handling set in Global.asax and web.config
Throw
End Try
End Sub
'Part of my ShoppingCart Class:
Public Class ShoppingCart
Private _items As List(Of OrderedProducts) = New List(Of OrderedProducts)
Public Sub New()
End Sub
Public Sub AddDB(ByVal product As Product, ByVal qty As Integer)
Dim orderedProd As OrderedProducts = New OrderedProducts(product, qty)
_items.Add(orderedProd)
End Sub
End Class
Public Shared ReadOnly Property ShoppingCart() As ShoppingCart
Get
If HttpContext.Current.Session("ShoppingCart") Is Nothing Then
HttpContext.Current.Session("ShoppingCart") = New ShoppingCart()
End If
Return CType(HttpContext.Current.Session("ShoppingCart"), ShoppingCart)
End Get
End Property
|
|
|
|
|
How can I truely get a date in the UK/GB format of dd/mm/yyy?
It's a dedicated server and everything is in GMT format as far as I can see, but nothing will change it to UK/GB format.
Any suggestions? I'd prefer to change a setting on the server than having an ASP .NET function, as it saves messing around.
Thanks,
Aaron
|
|
|
|
|
String.Format(yourDate, "dd/MM/yyyy")
Michael
I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious.
Vince Lombardi (1913-1970)
|
|
|
|
|
-Dr_X- wrote: String.Format(yourDate, "dd/MM/yyyy")
A slight correction:
String.Format("{0:dd/MM/yyyy}", yourDate)
---
single minded; short sighted; long gone;
|
|
|
|
|
Your locale settings determine the default date format. Region and Language settings in the control panel is what you need.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi All,
I am working on GridView.
I used sorting on two columns ASC/DESC alternatively, as usually it is done.
Everything works fine but After changing the Sorting order GridView Displays the desired order but on GVMaterialMaster_SelectedIndexChanging Event,
Code:
protected void GVMaterialMaster_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridViewRow row = GVMaterialMaster.Rows[e.NewSelectedIndex];
string materialCode = row.Cells[0].Text;
}
the row.Cells[0].Text always have value of row.Cells[0] of GridView before Sorting. Means row.Cells[0] always have the same value whether sorting is changed or not.
Any help is appreciated,
Thanks
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
Have you checked whether SelectedIndexChanging Event is firing??
|
|
|
|
|
Thanks Venkatesh for Reply
Yes GVMaterialMaster_SelectedIndexChanging Event is firing on Selection.
Sorting on a cloumn change the order of rows of grids Rows but in SelectedIndexChanging Event of Gridview Value
of row.Cells[0].Text remains as it is before sorting.
Example: GridView's first Row's first cell has value 'A' and Last Row's first cell has value 'X'
Now after sorting GridView is showing first Row's first Cell's value 'X' and Last Row's first cell has value 'A'. Its fine.
Now I Select First Row so It Shold show value of row.Cells[0] as 'X' but It is showing value of row.Cells[0] as 'A'.
So Any Idea why It is not have row.Cells[0] in desird order ?
Thanks Again for kind help.
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
Keep track of the RowIndex when you select the row. When sorting is done, just get the value in the copied RowIndex.
|
|
|
|
|
I am creating DataView(Runtime) and bind the GridView for Sorting.
Is it the cause of Problem?
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
The following variations (and more) fail to display correctly. Want to have the HeaderText property in the aspx page obtain a value from the code behind page.
Any ideas?
asp:BoundField DataField="Cargo" HeaderText='<% BL.Translate("Cargos") %>' SortExpression="Cargo"
asp:BoundField DataField="Cargo" HeaderText='<% =BL.Translate("Cargos") %>' SortExpression="Cargo"
asp:BoundField DataField="Cargo" HeaderText=<% BL.Translate("Cargos") %> SortExpression="Cargo"
Thanks,
Michael
I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious.
Vince Lombardi (1913-1970)
|
|
|
|
|
You cannot use Inline Coding in Server Controls.
Use RowDataBound or DataBound Event of the GridView Control to set its HeaderText.
|
|
|
|
|
Are there any standards out there on the best practices for how to pass object properties from the page to a user control?
For example, lets say I have a Person class with FirstName and LastName properties. Now say I wanted to display those attributes on a PersonDisplay user control. Should I be passing the control the Person object itself, or just the Person.FirstName and Person.LastName values? I've always done the latter, but wanted to see if there are any best practices or guidelines out there I should be following.
Thanks in advance
john miller
web developer
|
|
|
|
|
I made a httphandler for .asp pages to redirect to .aspx page of the same name. It works in cassini from VS2005, it works in IIS on XP on my dev box, but does not work in IIS in server 2003 in staging (or production). I had to change the mapping of .asp to aspnet_isapi.dll in the IIS config for the virtual directory to make it work on XP, and I did the exact same thing in server 2003, but I get a page not found error anyway. Is there some other step I need to take with server 2003 to have .asp requests handled by the .net framework so my handler can catch .asp pages?
|
|
|
|