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;
}
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;
}