473,395 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

databind a gridview to a dictionary<string, string> only shows 1 row?

I don't know if this is even working or not but here is the problem. I have
a gridview that I databound to a dictionary<string, stringcollection:

Contract StockContract = new Contract();
StockContract.Dictionary = ContractDictionary<string, string>();
GridView1.DataSource=StockContract.Dictionary;

So far so good. Now I assign something to the Dictionary collection through
some textboxes and a button:

protected void AddDefinitionButton_Click(object Sender, EventArgs e) {
StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);
GridView.DataBind();
}

The outcome is this: When I type into the 2 textboxes say, "test" for
WordTextBox and "first test" for DefinitionTextBox and hit the add button,
everything turns out fine. Now when I type in "clock" for the word and "you
tell time with it" for the definition and press the add button, the GridView
refreshes but with only 1 row instead of 2. What could be the problem? Here
is the code for the method I use for this. I'm not even sure if all of the
definitions are getting added to the dictionary collection the way they are
supposed to. Is there a way to find out if they are? Anyways, here is the
code for the method:

private void AddDefinition() {

///Todo: Add validation for adding duplicate words, empty values

string value = "";

StockContract.Dictionary = new ContractDictionary<string, string>();

//If the word already exists, do nothing except show a message saying the
word already exists.

if(StockContract.Dictionary.TryGetValue(WordTextBo x.Text, out value)) {

DefinitionList.Caption = "That word already exists, try again!";

}

else {

StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);

}

DefinitionList.DataSource = StockContract.Dictionary;

DefinitionList.DataBind();

WordTextBox.Text = String.Empty;

DefinitionTextBox.Text = String.Empty;

}


Jun 27 '08 #1
2 3106
On 25 Apr, 20:45, "Andy B" <a_bo...@sbcglobal.netwrote:
I don't know if this is even working or not but here is the problem. I have
a gridview that I databound to a dictionary<string, stringcollection:

Contract StockContract = new Contract();
StockContract.Dictionary = ContractDictionary<string, string>();
GridView1.DataSource=StockContract.Dictionary;

So far so good. Now I assign something to the Dictionary collection through
some textboxes and a button:

protected void AddDefinitionButton_Click(object Sender, EventArgs e) {
StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);
GridView.DataBind();

}

The outcome is this: When I type into the 2 textboxes say, "test" for
WordTextBox and "first test" for DefinitionTextBox and hit the add button,
everything turns out fine. Now when I type in "clock" for the word and "you
tell time with it" for the definition and press the add button, the GridView
refreshes but with only 1 row instead of 2. What could be the problem? Here
is the code for the method I use for this. I'm not even sure if all of the
definitions are getting added to the dictionary collection the way they are
supposed to. Is there a way to find out if they are? Anyways, here is the
code for the method:

private void AddDefinition() {

///Todo: Add validation for adding duplicate words, empty values

string value = "";

StockContract.Dictionary = new ContractDictionary<string, string>();

//If the word already exists, do nothing except show a message saying the
word already exists.

if(StockContract.Dictionary.TryGetValue(WordTextBo x.Text, out value)) {

DefinitionList.Caption = "That word already exists, try again!";

}

else {

StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);

}

DefinitionList.DataSource = StockContract.Dictionary;

DefinitionList.DataBind();

WordTextBox.Text = String.Empty;

DefinitionTextBox.Text = String.Empty;

}- Hide quoted text -

- Show quoted text -
Why are you using a dictionary list instead of a DataTable?
Jun 27 '08 #2
How easy is it to serialize a DataTable contents to an xml file as part of a
larger object to be serialized?

I have the object Contract that has many, many different parts to it. One of
those parts is a dictionary (glossary) and a contract sections (the
different parts that make up the text of the contract object). This whole
contract object must be serialized, digitally signed eventually and then
inserted in a database as an xml field. Can you do all of this by using
dataTables as object properties? The other condition to all of this is that
it can be taken out of the database as an xml object, deserialized from the
xml object back into the contract object and then reused again.
"Stan" <go****@philphall.me.ukwrote in message
news:ac**********************************@x41g2000 hsb.googlegroups.com...
On 25 Apr, 20:45, "Andy B" <a_bo...@sbcglobal.netwrote:
>I don't know if this is even working or not but here is the problem. I
have
a gridview that I databound to a dictionary<string, stringcollection:

Contract StockContract = new Contract();
StockContract.Dictionary = ContractDictionary<string, string>();
GridView1.DataSource=StockContract.Dictionary;

So far so good. Now I assign something to the Dictionary collection
through
some textboxes and a button:

protected void AddDefinitionButton_Click(object Sender, EventArgs e) {
StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);
GridView.DataBind();

}

The outcome is this: When I type into the 2 textboxes say, "test" for
WordTextBox and "first test" for DefinitionTextBox and hit the add
button,
everything turns out fine. Now when I type in "clock" for the word and
"you
tell time with it" for the definition and press the add button, the
GridView
refreshes but with only 1 row instead of 2. What could be the problem?
Here
is the code for the method I use for this. I'm not even sure if all of
the
definitions are getting added to the dictionary collection the way they
are
supposed to. Is there a way to find out if they are? Anyways, here is the
code for the method:

private void AddDefinition() {

///Todo: Add validation for adding duplicate words, empty values

string value = "";

StockContract.Dictionary = new ContractDictionary<string, string>();

//If the word already exists, do nothing except show a message saying the
word already exists.

if(StockContract.Dictionary.TryGetValue(WordTextB ox.Text, out value)) {

DefinitionList.Caption = "That word already exists, try again!";

}

else {

StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);

}

DefinitionList.DataSource = StockContract.Dictionary;

DefinitionList.DataBind();

WordTextBox.Text = String.Empty;

DefinitionTextBox.Text = String.Empty;

}- Hide quoted text -

- Show quoted text -

Why are you using a dictionary list instead of a DataTable?

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joanna Carter \(TeamB\) | last post by:
I would like to copy the contents of a Dictionary<string, object> to another Dictionary<string, object>. Do I have to iterate the source use something like foreach or is there an easier way ? ...
7
by: Wilson | last post by:
Hi, How do get the Dictioanry object from FiedlInfo ? my code : fieldInfo = this.GetType().GetField("dictioanry1"); ??Dictionary<string, string> dicTemp1 = (Dictionary<string,...
6
by: buzzweetman | last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the list of keys out of it as a List<string>, to pass to a another method that expects a List<string>. I often do the following: ...
4
by: Mark Rae | last post by:
Hi, Is it possible to create a case-insensitive List<stringcollection? E.g. List<stringMyList = new List<string>; MyList.Add("MyString"); So that:
4
by: Maikeru | last post by:
I am trying to create a map that contains a string as the key and a list of strings as the value. Essentially it will be a dictionary where the key is an English word and the list will contain all...
2
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the...
2
by: Andy B | last post by:
Is it possible to serialize to xml a dictionary<string, stringobject in ..net 3.5?
6
by: Paul.N.Phillips | last post by:
I am using a static dictionary to objects (like cache) but woundered if it is better to use cache. Which one would should I use?
2
by: jandeerit | last post by:
hi... can anyone help to show me how to store the array in a dictionary object as shown below? FROM: Array : "PARAMETERS" : "ParamName-1" : "ParamValue-1" : "ParamName-2" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.