Skip to content
Loading
  • 0
    Hi Jangid!
     
    I try your code , but when i show my form, dropdownlist not show value " selected" (Which value of CATID in table NEWS) 
    0
  • Rafnas T P
    0
    hi,
     
    selected value give category Id from News Table
    try changing code as shown below
     
     
    1. try    
    2. {    
    3. SqlConnection conn = new SqlConnection(connStr);    
    4. SqlDataReader reader = null;    
    5. conn.Open();    
    6. string sql = "SELECT * FROM NEWS where NewsID= " + sid + "";    
    7. SqlCommand comm = new SqlCommand();    
    8. comm.Connection = conn;    
    9. comm.CommandText = sql;    
    10. reader = comm.ExecuteReader();    
    11. while (reader.Read())    
    12. {    
    13. string Newsid = reader.GetValue(reader.GetOrdinal("Newsid")).ToString();    
    14. string CatID = reader.GetValue(reader.GetOrdinal("CatID")).ToString();    
    15. string Title = reader.GetValue(reader.GetOrdinal("Title")).ToString();    
    16. string Content = reader.GetValue(reader.GetOrdinal("Content")).ToString();    
    17. if (Newsid != "")    
    18. {    
    19. SqlDataReader reader = null;    
    20. string sql = "SELECT CatID, CatName FROM Category order by Catid desc";    
    21. SqlCommand comm = new SqlCommand();    
    22. comm.Connection = conn;    
    23. comm.CommandText = sql;    
    24. reader = comm.ExecuteReader();    
    25. while (reader.Read())    
    26. { 
    27. Dropdownlist.DataSource = reader;    
    28. Dropdownlist.DataValueField = "CatID";    
    29. Dropdownlist.DataTextField = "CatName";    
    30. Dropdownlist.DataBind();
    31. }  
    32. Dropdownlist.SelectedValue = CatID ;      
    33. }    
    34. }   
    0
  • 0
    Hi Ramas!
     
    It's  OKIE. 
    Thank you very much 
    0