Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi iam getting subcategorynames in a dataset and assigning that dataset to a datalist with checkboxes.my requirement is when assigning datset to datalist i have check a condition..that subcategories are present in another datalist are not..if have that checkboxes are checked otherwise unchecked..how can i check it help me...

my aspx page is:
XML
<asp:Content ID="Content3" ContentPlaceHolderID="MainContentPanel" runat="Server">
    <table width="100%" cellpadding="0px" cellspacing="0px" border="0">
        <tr>
            <td align="center">
                <table border="0" cellpadding="0" cellspacing="0" width="600px" class="userpanel">
                    <tr>
                        <td class="tahoma11boldwhite" bgcolor="#86b2bb" height="20" align="center">
                            <asp:Label ID="Label1" runat="server" Text="Edit More Suibcategories"></asp:Label>
                        </td>
                    </tr>

                    <tr>
                        <td align="center" valign="top">
                            <asp:Panel ID="panelPostListings" runat="server">
                                <table border="0" cellpadding="0" cellspacing="2" width="100%">
                                    <tr class="AlternateRowStyle">
                                        <td class="tdStyle">
                                            YPID
                                        </td>
                                        <td class="tdStyle">
                                            <asp:TextBox ID="txtYPID" runat="server" CssClass="TextBox" Width="250px" ReadOnly="true"></asp:TextBox>
                                        </td>
                                    </tr>
                                     <tr class="RowStyle">
                                        <td class="tdStyle">
                                           CompanyName
                                        </td>
                                        <td class="tdStyle">
                                            <asp:TextBox ID="txtCompanyName" runat="server" CssClass="TextBox" Width="250px" ReadOnly="true"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr class="RowStyle">
                                        <td class="tdStyle">
                                            Category
                                        </td>
                                        <td class="tdStyle">
                                            <asp:TextBox ID="txtCategory" runat="server" CssClass="TextBox" Width="250px" ReadOnly="true"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr class="AlternateRowStyle">
                                        <td class="tdStyle">
                                            SubCategory
                                        </td>
                                        <td class="tdStyle">
                                            <asp:TextBox ID="txtSubCategory" runat="server" CssClass="TextBox" Width="250px"
                                                ReadOnly="true"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr class="RowStyle">
                                        <td class="tdStyle" colspan="2">
                                            <asp:DataList ID="subcategorydatalist" runat="server" RepeatColumns="3" RepeatDirection="Vertical">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="chksubcategory" runat="server" Text='<%# Eval("SubCategory") %>' />
                                                </ItemTemplate>
                                            </asp:DataList>
                                        </td>
                                    </tr>
                                    <tr class="AlternateRowStyle">
                                        <td colspan="2" align="center">
                                            <asp:Button ID="btnSubmit" runat="server" Text="Submit"  />

                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>


aspx.cs:--
------------
C#
if (!IsPostBack)
       {
           dr = ABLOBJ.GetYPInformationListingByID(LPOBJ);
           if (dr.HasRows)
           {
               while (dr.Read())
               {
                   txtYPID.Text = dr["YPID"].ToString();
                   txtCategory.Text = dr["Category"] != null ? Convert.ToString(dr["Category"]) : "";
                   txtSubCategory.Text = dr["SubCategory"] != null ? Convert.ToString(dr["SubCategory"]) : "";
                   txtCompanyName.Text = dr["CompanyName"] != null ? Convert.ToString(dr["CompanyName"]) : "";
                   UPOBJ.U_Category = txtCategory.Text.ToString();
               }
           }
           ds = ABLOBJ.GetRelatedSubCategories(UPOBJ);
           ds1 = ABLOBJ.GetSelectedSubCategories(LPOBJ);


           subcategorydatalist.DataSource = ds;
           subcategorydatalist.DataBind();

       }

   }



this is editsubcateories apge..here iam dispalying categoryname and all subcategories present in that category using datalist..

in ds iam getting total subcategories..here i want to show user already he seelcted subcategories as checked.for taht iam getting his selected subcategories to ds1.my requirement is when iam assigning ds to datalist i want to check taht any subcategories are present in ds1..taht subcategories will be checked remaining are unchecked..plz help me in writing the code.
Posted
Updated 22-Apr-11 20:20pm
v2
Comments
[no name] 23-Apr-11 2:01am    
can you be more specific and show your code for what you did and what you want to do.
BHANU PRAKASH BYSANI 23-Apr-11 2:21am    
i updated my question .plz check once
Oshtri Deka 23-Apr-11 3:33am    
No offense, but it isn't easy to read your question.

1 solution

There is difference between DbNull.Value and null.

"Do not confuse the notion of null in an object-oriented programming language with a DBNull object. In an object-oriented programming language, null means the absence of a reference to an object. DBNull represents an uninitialized variant or nonexistent database column."

If there is possibility that your query returns NULL (nonexistent value for any column) you should compare values in dataReader with DBNUll.Value.
Oversimplified conclusion is: null is for general OOP and DBNull.Value is ADO.Net

C#
someControl.Text = dr.ISDBNull(indexOfMyColumn) ? "" : dr["myColumnName"].ToString();


Firendly advice:
Use try/catch block and always close dataReader!

P.S.
if (dr.HasRows) condition is redundant, check why ;).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900