i am getting this error while tracking my datakey.. i am not sure why my datakey index is coming out of range.. here is my code :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
var dataKeys = GridView1.DataKeys[e.Row.RowIndex];
dataKeys.Value.ToString();
Label1.Text = "The key field value for the displayed record is " + dataKeys.Value.ToString();
}
I am binding SQL data to a GridView. The GridView's DataKeyNames property is set to the SQL column called "utID"
I know that within the SQL results, some of the utID values are NULL. After databinding to the GridView, I need to enumerate through the GridViewRows an read the DataKey values. However, when I try this I get the following error:
No default member found for type 'DBNull'. I am using the code below.
What object types are stored within DataKeys (I thought it was just integers or strings)
How to handle a NULL datakey value to prevent this error occurring?
I don't want to use Try Catch because it's too much of a 'hack'
I have a GridView with an associated DataKey, which is the item ID. How do I retrieve that value inside the RowCommand event?
This seems to work, but I don't like the cast to LinkButton (what if some other command is firing the event?), and I'm not too confident about the NamingContainer bit.
LinkButton lb = (LinkButton)e.CommandSource; GridViewRow gvr = (GridViewRow)lb.NamingContainer; int id = (int)grid.DataKeys[gvr.RowIndex].Value;
I'm aware that I could instead pass that ID as the CommandArgument, but I chose to use DataKey to give me more flexibility.
I'm also aware that it's possible to use a hidden field for the ID, but I consider that a hack that I don't want to use.
What seems to happen is 'GridView1_RowUpdating' gets fired, at this point newEnglish, newFrench, and newGerman all have the new values as they are passed into 'Logic.Update'. Then the update functions updates correctly, but once the 'GridView1_RowUpdating' sub ends, it seems to call Logic.Update another time, and this is where the new values get lost for French and German (datakeys) but not English.
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating Dim newEnglish As String Dim newFrench As String
And bind gridview from this table and ordred by Preference Column I put Linknbutton in gridview that code is:
protected void LinkButton11_Click(object sender, EventArgs e) { GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow; int id = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value); using (SqlConnection conn = General.GetConnection()) {
[Code] .....
Oroblem is in this line:
int id = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);
I want when I click on linkbutton it use Id but here it use Preference data How I can define that according to Id column it go to
Is it possible to track bugs in a visual web developer website? I want to be able to step through the code so I can see exactly what it is doing but am not quite sure how to do this.
Yesterday i saw a site in which, site is listing the ip address and country name, saying that recently visited members (a list of ip address with country name,city name). Can i know how can i track that information any reference or any code.
<IMG src="filepate of image" alt="Click to view this company's profile" [code]...
Above is the html code. The code says it has a picture which has two links. Now can anyone tell me how can i track on the click on image for a perticular url. Using asp.net say url1. I need to store the clicks report into the database using vb.net.
I have a ASP.Net wesite developed using c#, ASP.Net,Oracle and Ajax.I want to send an email to the user from HP Quality Center (QC) and get the result from the user and store it the Quality Center Defect.QC will automatically send the email.The user should be able to provide the result like (Yes/No) even from his mobile by accessing the email or a system.How can we keep track of the reply send by the user and using which method?I can take the help of my ASP.Net website to route the message.For Example, when the user send the reply,the website should be some how able to parse the email and store this into QC or database.
after my grid view updates a record I would like to run some code, I have tried to use SelectedDataKey.Value.ToString() to get the datakey. However it is null, the record updates so the value must be stored somehow?
I have done this before "n" number of times but I am not able to get it working this time. The trouble is that when the call for the Select Method of the formview goes to the relevant function - "GetCustomerByCusnum" I have a null value in its parameter "cusnum".
I know that I can write a selecting event and using CommandArgument, parse the value of the selected row and pass it into the Select method as a value but I dont want that solution. I know it works without the "Selecting" method but I cant recall how.
I have the DataKey value, I want to use that to get the GridViewRow and retrieve information from various columns - I see lots on information on how to get the datakey from a gridview row, but not the reverse.
For the first page loaded, it shows the correct DataKey value if I click on the command field.
However if I change to the next page of results, upon selecting a record the corresponding value is incorrect. It seems to keep the previous page information. How do I overcome this?
EDIT:
In the GridView1_SelectedIndexChanged method, I used the following:
[Code].....
I am unable to get the correct value after paging.
I have a situation where I needed to add a row to my gridview. So say I have rows 3, 4 and 5.
My Datakeys are defined as "ID, CostingID". I did that so I can reference the two ID values I need when saving records.
here is the code in my RowDataBound event.
Basically if it is a datarow, I'm adding the value dataitems so I can get a sub total in the footer row.
Then, I have a boolean field called isDisbursement. So I sort my data by that field. So all records with the disbursement flag as true will display first.
Then as soon as the disbursement flag hits false I add a row to display the Total of the disbursement records value field.
All this works. My problem is, because I added a row at index 4 it inherits the datakey of the row that was at index 4 before. So when I'm looping through the grid rows to save the values I'm having a problem. I've attached an image so you will understand better what I'm trying to achieve. The "Total Disbursements" is the row I added. But it gets the following rows datakey because it is now at index 4.
when I do this, as soon as I reach row 4, although it doesn't have a CostingID it gets the CostingID of row 5 that used to be row 4:
Code: Dim CostingID As Long = Convert.ToInt64(Me.grvCostings.DataKeys(row.RowIndex).Values("CostingID").ToString) Dim strValue As String = CType(row.FindControl("txtValue"), TextBox).Text
Code: If e.Row.RowType = DataControlRowType.DataRow Then If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "value")) Then _SubTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, _ "value")) End If
Is there a (free!) software/components that I can use to track how my web site is being used - which pages are most popular, how many times was the site visitied today, yesterday etc...
I am using sql server 2005 on my local PC. I have the same copy of the database on a shared hosting environment.I need to transfer daily transaction on some tables in my local database to the remote database. My remote database ison the shared hosting environment so i don't have much control on it.
I want to capture all the DML statement on tables and then at the end of day will execute those DML statement on theremote database.Kindly suggest how can i trace DML statement on database tables.
I have POCO's in a separate project and now I need Self Tracking Entities. Does anyone know if I need to generate new POCO's that are self tracking and they will replace my current POCO's? Or, do I setup self tracking entities in addition to my current POCO's?
I am planning to build a custom web application in ASP.NET 4.0 using WF 4.0, the user wants ability to modify workflows himself, for this we will be using a WPF client which the user can use and we will do workflow re-hosting, lots of blogs and guidance is available for this. But I am not sure how to the meet one requirement where the user wants to see/track a visual representation (diagram/image) of the workflow, depicting what stages are over, what is the current stage etc. This needs to be done on a web page.Possibly the same workflow with icons depicting status. This is something similar to the visual available for Visio workflows in SharePoint 2010. Even AgilePoint workflows provide such a view.
Is there any way of tracking EF entities changes between contexts for ASP.NET applications?
Self-Tracking entities doesn't work well for me as it is primarily designed for WCF. And all approaches for tracking changes for POCO I have found are oriented on shared context.
The FormView is bound to the same ObjectDataSource as the GridView and the FormView uses the autoPaging so I can't just use a separate DataSource for the FormView with just one parameter being the ID.
There must be a way to set the FormView PageIndex by a Datakey value.