is it possible to validate specific cells within a gridview, without generating complete new emptyrow-templates or edit-templates. this is very frustrating as i only need to validate just 2 cells out of 25.
thanks for helpingIf you want to use the Validation controls, you must use templates where you add the validation controls, there are no built in validation for the boundfiled. You can also use the events, such as updating, inserting of the data source control to build your own validation and cancel the command if the validation fails.
yes, this is what i thought, too.
for the last two days i've been fiddling around with the lookup-tables and validation of gridviews. i am stuck and desparately need your help.
at this point i have to say that your support is really great! i don't know if i would have learnt asp.net 2.0 (before that i only developed with ms access vb) that fast without your help or the help of other members of this forum
now back to my problem; i am using now simple examples for a better understanding:
i have a table with name, firstname, salutationID and so on in a table tblContact.
the salutation-value is in a lookuptable tblSalutation (SalutationID and Salutation are the fileds) this means tblContact only contains a number which represents a value in another table.
when opening the gridview for tblContact, it should display the following:
in normal mode: name, firstname, Salutation (not the SalutationID)
in edit mode: name, firstname, dropdownlist of all items within tblSalutation (but here's the big difference now: the dropdownlist shouldnot display the ID, but the field Salutation)
when updating the row, the corresponding ID to the selected Salutation should be stored in field tblContact.salutationid.
if you have developed in ms access there is a way of defining a dropdownlist containing multiple fields from a different source and you choose the column which will be used for other purposes (eg saving in another field).
i already know some bits and pieces how to do that
- selecting for the dropdownlist a second sqldatasource
- assigning the value of the dropdownlist to the field tblcontact.salutationid needs to be done on server side eg. using the onupdating event of the datagrid or onselectedindexchanged event of the dropdownlist.
but i am stuck. maybe this isnt just possible.
btw i really prefer to do this with gridview and not with formsview as i try to keep it plain and simple. if you have code examples, my language is vb.
thanks a LOT
The following code will use the Salutation field as the Text of the items in the DropDownList and the value of the item will be the value from the SalutationID:
<asp:DropDownList DataTextField="Salutation" DataValueField="SalutationID" SelectedValue='<%# Bind("SaluationID")' ....
When you bind a field to the SelectedValue proeprty of the DropDownList, the selected value will be passed to the @.SalutationID parameter of the UpdateCommand or InsertCommand.
You don't need to use any event to get the value or set the values.
thank you so much fredrik.
that way was also one of my first attempts but did not work as i used eval instead of bind...
last question: in normal mode (or view mode) i like to use a texbox (or anything similiar) instead.
can i do this and if yes, how?
Add the TextBox into a ItemTemplate, and the DropDown into a EditTemplate/InsertTemplate.
hi fredrik,
i need something which looks in normal mode like the other columns but displays the value of the lookuptable which is not a member of the gridview's datasource.
what you have suggested means to create a join for the gridview's datasource?
yes, that would work but as this is a huge gridview i would have to create a join to 4 lookup-tables...
Can you be more specific of your problem?
For example what do you want to accomplish?
hi fredrik,
the problem is still the one from above. i am using a simple example for a better understanding:
i have a table with name, firstname, salutationID and so on in a table tblContact.
the salutation-value is in a lookuptable tblSalutation (SalutationID and Salutation are the fileds) this means tblContact only contains a number which represents a value in another table.
the gridview should display name, firstname, Salutation (not the SalutationID)
as i said, it would be easy to handle this by creating a join select on the gridview's sqldatasource. but then i would have to do 4 join selects.
Why do you need four joins? If you want to get the text for the salutationID, don't you only need to join the table where the salutation is located?
sure, but i have 4 more fields whose value is represented in 4 other lookuptables.
let me explain this with the example of above:
tblContact: name, firstname, salutationid (refers to salutation in lookuptable1), positionid (refers to position in lookuptable2), countryid (refers to country in lookuptable3), titelid refers to titel in lookuptable4), and so on...
No comments:
Post a Comment