Hi all,
i have a hashtable which i have bounded to detailsview.. it is fine.
but i donno what code should i use now to display the values of that hashlist on labels in my details view. -
hshTable .Add("UserLevel", UserLevel);
-
hshTable .Add("TypeLevel", TypeLevel);
-
hshTable .Add("ActionLevel", ActionLevel);
-
hshTable.Add("StatusLevel", StatusLevel);
-
-
DetailsView1.DataSource = ashTable;
-
DetailsView1.DataBind();
now how can i display these values on labels in my template column in my detailsview??
please help
thanks,
vineet
12 5322
Hi bineetbindal,
I tried myself to bind a detailsview to a hashtable. But this did not work. It threw the following error: DetailsView with id 'dvwTest' did not have any properties or attributes from which to generate fields. Ensure that your data source has content.
This means hashtable is non-bindable datasource. I guess one work around would be to create a datatable with hashtable-keys as columns and hashtable-values as column-values. And then bind the gridview or detailsview to this datatable.
But I am keen to know if you have succeeded to bind the detailsview to the hashtable. Waiting your response, thanks.
HI,
I tried a lot but i was not able to do it, actually i am working on asp.net after few years, can you give me some code about how can i do it with datatable?
actually the difficulty i am facing is --- i have a gridview. when a person clicks on the gridview. i have to display all the values of that row on the lables in details view(those labels are in tempalte column in detailsview). i am able to do that with the code below. till the time detailsview is in insertmode. - //get the vales from the grid's selected row
-
Label User = (Label)GridView1.SelectedRow.Cells[6].FindControl("lblUserLevel");
-
Label Action = (Label)GridView1.SelectedRow.Cells[7].FindControl("lblActionLevel");
-
Label Type = (Label)GridView1.SelectedRow.Cells[8].FindControl("lblTypeLevel");
-
Label Status = (Label)GridView1.SelectedRow.Cells[9].FindControl("lblStatusLevel");
-
//convert those grid values to string
-
string UserLevel = User.Text;
-
string ActionLevel = Action.Text;
-
string TypeLevel = Type.Text;
-
string StatusLevel = Status.Text;
-
//find label in detailsview and assign them values
-
((Label)DetailsView1.FindControl("lblUser")).Text=UserLevel;//here it throws error if i chnage the defoultmode ffrom insert to anything else.
-
((Label)DetailsView1.FindControl("lblAction")).Text = ActionLevel;
-
((Label)DetailsView1.FindControl("lblType")).Text = TypeLevel;
-
((Label)DetailsView1.FindControl("lblStatus")).Text = StatusLevel;
but as soon as change the defoultmode of detailsview from insert to anything else, it stops working. it also stops working even if i try to put a <EditItemTemplate></EditItemTemplate> in my detailsview.
i am not able to understand why it behaves so dramatically, i have been searching on the behavious of detailsview but did not get anything.
thats why i tried to bind it by putting vallues in hashtable but unsuccessfull.
can you give me an example how can i do it with datatable(some code will be really appreciatable.)
regards,
Vineet
Have you checked out the DetailsView class on MSDN?
There are some examples there on how to use the DetailsView with a SqlDataSource as it's source (which connects to a database).
yes i did,
here i am not using any SqlDataSource as its source.
my source is a row in my gridview.
thats what the problem is
Could you please post the ASP code that you're using so I can see what your doing?
below is my aspx file.
below is my code behind or cs file..
Ok, quickly looking at this, I see one thing that can be causing a problem with your editing.
In your PageLoad event you have: -
if (Page.IsPostBack)
-
GridView1.DataBind();
This could be causing problems.
Move this to the PreRender event instead and see if that makes a difference.
No it still does not make any differance.
it is still the same.
it works without <EditItemTemplate></EditItemTemplate> but as soon as i add one in my detailsview or change the defoultmode from insert to anything else it throws me an error in one of the lines
((Label)DetailsView1.FindControl("lblUser")).Text = UserLevel;
((Label)DetailsView1.FindControl("lblAction")).Tex t = ActionLevel;
((Label)DetailsView1.FindControl("lblType")).Text = TypeLevel;
((Label)DetailsView1.FindControl("lblStatus")).Tex t = StatusLevel;
depending on in which column i put the <EditItemTemplate></EditItemTemplate>
or if i am changing the mode then it gives me an error in the first line.
hi i tried doing it as suggested by Sangam, through datatable and that thing works fine.... thanks a lot for that. but i am still confused why it did not work the way i was oing it, wht it was working fine with insert mode without edittemplatecolumn and why not viceversa.
Hi Vineetbandal,
I suspect null reference exception is being thrown while finding the labels in edit mode.I suggest to put the edit mode specific code in the particular section in the databound event hander of the detailsview, like this: -
-
-
//Databound event handler for the detailsview
-
protected void DetailsView1_DataBound(object sender, EventArgs e)
-
{
-
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
-
{
-
//tasks related to insert mode only
-
}
-
else if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
-
{
-
//tasks related to edit mode only
-
//*** Here I have inserted your code
-
((Label)DetailsView1.FindControl("lblUser")).Text = UserLevel;
-
((Label)DetailsView1.FindControl("lblAction")).Text = ActionLevel;
-
((Label)DetailsView1.FindControl("lblType")).Text = TypeLevel;
-
((Label)DetailsView1.FindControl("lblStatus")).Text = StatusLevel;
-
}
-
}
-
Hope this helps.
Please follow up if no progress. Thanks.
Hi thanks a lot for the effort.. but i tried the solution u gave me before saving the values in a datatable and binding it to the detailsview and works absolutely fine//... but i have another problem now... when i clikc on edit button in my detailsview .....it just says... EmptyDataText="There are no records." and it is supposed to show the dropdowns in the detailsview.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ceri_Davies |
last post by:
Hi, Is it possible to bind a text box to the results of a detailsview
record. This is for a university project using visual web developer 2005
express beta. Unfortunatly this is a new eniroment to...
|
by: Andrew Robinson |
last post by:
Is there any way to accomplish two way data binding in a Details View with a
DataSet or DataTable as the DataSource.
All I want is to get an updated DataSet or DataTable back from the...
|
by: Timm |
last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative
data binding wherever possible and trying to minimize the use of code. The
list of values in DropDownList DDL2 should be...
|
by: Dave |
last post by:
Hi all,
Is it possible to populate a listbox from a hashtable (complexbind) where
the ValueMember of the listbox maps to the "key" member of the hashtable AND
the DisplayMember of the listbox maps...
|
by: aarnan |
last post by:
I have two SqlDataSources that use two different stored procedures that
take parameters to populate two controls, one dependant on an element
of the other.
The first data source,...
|
by: 47computers |
last post by:
Hello. I'm having a bit of difficulty with some DropDownList controls
within templates in a DetailsView on my web form. Basically, I have a
form where a user is building a "location profile" with...
|
by: JJ |
last post by:
Hi.
I am having trouble getting a dropdownlist to work properly in a
detailsview:
The code is something like:
<asp:DetailsView ID="dvwSubscriber" runat="server" AutoGenerateRows="False"
...
|
by: makennedy |
last post by:
Hi Experts,
Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere.
Basically I have a TreeView Control which I have created...
|
by: vineetbindal |
last post by:
Hi all,
I have a datagrid and detailsview. when a user selects a row in datagrid onSelectedIndexchanged is fired and Detailsview comes into picture. I want to display the data of the selected row...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |