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

  • Thread starter Thread starter Andy B
  • Start date Start date
A

Andy B

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, string> collection:

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(WordTextBox.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;

}
 
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, string> collection:

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(WordTextBox.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?
 
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.
 
Back
Top