By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,125 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,125 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.