Mauricio Feijo's WebLog

February 2004 - Posts

.NET Cocktails

http://www.in-the-spirit.co.uk/index.html

If you like cocktails, you need to see this..

Datagrid inserting rows question.

I am always looking for better solutions for a quick and clean code for table maintenance.

More for fun than anything I am writing a table maintenance page using datagrid. I am trying to keep it as abstract as possible, as I will later add other tables and reuse most code, or maybe wrap it in a custom control.

The datagrid is sorting asc and desc in all columns ( displaying an arrow showing the direction), allowing the user to pick how many rows to be displayed at a time, editing and deleting.

I want to make it insert too, and for that I have a button outside the datagrid, “Add Row“, that when clicked adds an empty row to the top of the dataset, saves the dataset, set currentpageindex and edititemindex and binds.

Private Sub btnAddRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddRow.Click
SqlDataAdapter_store.Fill(DataSet_store)
Dim dr As DataRow = Me.DataSet_store.atr_store.NewRow
dr("store") = ""
dr("size") = ""
dr("active") =
True
Me.DataSet_store.atr_store.Rows.InsertAt(dr, 0)
Session("DataSet_store") = DataSet_store
dgStores.CurrentPageIndex = 0
dgStores.EditItemIndex = 0
viewstate("Operation") = "INSERT"
Binddata(
True)
End Sub

The problem I am finding is with the primary key column.
Before get to the insert part, I had it as a bound column, only showing the data (“store“). But using this approach to insert rows I need to have a textbox in the edititemteplate tag in that column, and the column needs to be a template column instead of databound column. All obvious, no problem.

But now when editing the “store“ textbox is available too.

I cannot make it readonly or disabled or invisible because either it hasn't been rendered yet and it doesn't exist, or it has been rendered and then it is too late to change it's attributes.

Also, I am trying to avoid adding client script to change the box attribute to read only after the page loads. I don't think it is elegant, and will probably byte me back..

I hate asking obvious questions about simple scenarios, but someone have a word on this?

Thanks

 

-Mauricio

Posted: Feb 04 2004, 05:21 PM by Mauricio Feijo | with 9 comment(s)
Filed under:
Languages

While living in the US for 6 years, I am Brazilian and my natural language is Portuguese. Most Brazilians living in US speak (or at least we think we do) Spanish and English. That gives us a trilingual status.  Also, among Europeans it is normal to speak at least 3 languages. I bet Dino Esposito doesn't speak only Italian and English.

So the above is to make a point that I DO NOT have anything against other language speakers,

But English is THE Universal Language. It is not the most spoken in the world (1-Chinese, 2-Spanish, 3-English), it is probably the most understood in the IT Software Development Community. ( Most programming languages incorporate English commands and operators with their own syntax elements.)

I read this post from Rido, Bye Bye nAnt, and thought it would be interesting to the professional responsible for builds at my current contract to read it, but he speaks exclusively English. So either I ( or someone else)  translate it for him, or he can't read it at all. )

That is a good example of why I am taking my time to write this post. While we all like to use our own languages, we may be preventing some people from reading  and understanding.

Just a thought.

BTW, anyone was at the last Atlanta.NET meeting at Microsoft last week? Stuart Dickerson did a great job showing some UI tips ( a lot about Datagrid. Get his code here.) and Doug Ware kicked a** talking about Continuous Integration and Automated Unit Testing. He had a great example about incorporating source control applications, DRACO.NET , nAnt , nUnit and  nDoc to create continuous integration. IT becomes sort of a Build Engine, with all the steps in the middle well controlled. He mentioned http://sourceforge.net/ as the place to get some of these pieces.

More Posts