开发者

Retrieving DropDownList 'value' (C#/ASP.NET)

On my page, whenever a DetailsView is updated, I must audit the changes into a database. On most pages this works perfect, as there were just textboxes - however on a page I am working on right now, with dropdownlists, my code isn't working.

Basically, what the code does is captures the Updating event of the SqlDataSource, creates a datareader to look at the contents of the row before it's updated, compares the contents to the parameters in the Update query of the SqlDataSource, and if one has changed to log this in a field in the Audit table. An extract of my code is below:

while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
           try {
                        if开发者_高级运维 (reader[i].ToString() != e.Command.Parameters[i].Value.ToString())
                        {
                            fields[i] = reader.GetName(i) + ": " + reader[i].ToString() + " => " + e.Command.Parameters[i].Value.ToString();
                        }
           }
                    catch {
                        if (reader[i].ToString() != "")
                        {
                            fields[i] = reader.GetName(i) + ": " + reader[i].ToString() + " => ";
                        }
                    }


                }
            }

When the control is on a dropdownlist, it seems to never go 'into' the IF even though the fields are different. Do I need to do something special to compare the values of dropdownlists? Note I believe the value is stored as an int in my table.

Thanks


Totally my fault. There was an extra parameter on the command which I had to exclude somehow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜