Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,
i have gridview have 6 columns on of these column is checklistbox in editetemplate and in itemtemplate ,
the datasource of checklistbox in itemptemplate is diffrent of the the datasource in edittemplate
the problem is in page load when binding gridview the gridview is appear with an empty row and then another row empty from all cells except column having checklist
then row all cells having value but checklist column is empty
how can i fix this
i want all cells appear in the same row with their values

this is my grid view code :
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 
                    CellPadding="4">
                    <Columns>
                        <asp:TemplateField HeaderText="نوع التعليم">
                            <EditItemTemplate>
                                <asp:Label ID="lbl_edu_type" runat="server" Text='<%# Bind("edu_type_id") %>'></asp:Label>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("edu_type_id") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="رقم  الترخيص">
                            <EditItemTemplate>
                                <asp:Label ID="lblold_number" runat="server" 
                                    Text='<%# Bind("old_lisense_number") %>'></asp:Label>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("old_lisense_number") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="تاريخ تأسيس  المدرسه ">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtold_lisense_date" runat="server" 
                                    Text='<%# Bind("old_lisense_date") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Bind("old_lisense_date") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="تاريخ بداية الرخصه الحاليه ">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtold_start_lisense_date" runat="server" 
                                    Text='<%# Bind("lisenses_date") %>'></asp:TextBox>
                            </EditItemTemplate>
                            
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("lisenses_date") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="تاريخ نهاية الرخصه الحاليه ">
                            <EditItemTemplate>
                                <asp:TextBox ID="txt_current_old_lisense_date" runat="server" 
                                    Text='<%# Bind("lisensee_date") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("lisensee_date") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="المراحل الدراسيه ">
                            <EditItemTemplate>
                                <asp:CheckBoxList ID="chlist_edit" runat="server"   RepeatColumns="3">
                                </asp:CheckBoxList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:CheckBoxList ID="chlist_item" runat="server" RepeatColumns="3"  >
                                </asp:CheckBoxList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True" />
                    </Columns>
                    <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                    <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                    <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                    <RowStyle BackColor="White" ForeColor="#003399" />
                    <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                    <SortedAscendingCellStyle BackColor="#EDF6F6" />
                    <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
                    <SortedDescendingCellStyle BackColor="#D6DFDF" />
                    <SortedDescendingHeaderStyle BackColor="#002876" />
                </asp:GridView>
<pre lang="HTML">


in pageload the data of gridview retrevied from datasource but the data of checklist column retrevied from diffrent dataset :
VB
GridView1.DataSource = bal_obj.get_lisense_data(scholl_id)
               GridView1.DataBind()

i made event rowdatabound to bindchecklist in itemtemplate and in edittemplate

VB
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
       If e.Row.RowType = DataControlRowType.DataRow Then
           If (e.Row.RowState And DataControlRowState.Alternate) > 0 Then
               Dim chkBrand As CheckBoxList = DirectCast(e.Row.FindControl("chlist_item"), CheckBoxList)
               chkBrand.DataSource = bal_obj.get_school_stages(scholl_id)
               chkBrand.DataTextField = "stage_name"
               chkBrand.DataValueField = "stage_id"
               chkBrand.DataBind()
               ' chkBrand.SelectedValue = DirectCast(e.Row.DataItem,DataRowView)("BrandID").ToString()
           End If
           If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
               Dim chkBrand As CheckBoxList = DirectCast(e.Row.FindControl("chlist_edit"), CheckBoxList)
               chkBrand.DataSource = bal_obj.get_allstage()
               chkBrand.DataTextField = "stage_name"
               chkBrand.DataValueField = "stage_id"
               chkBrand.DataBind()
               ' chkBrand.SelectedValue = DirectCast(e.Row.DataItem,DataRowView)("BrandID").ToString()
           End If
       End If
   End Sub
Posted
Comments
Abhijit Ghosh (Subho) 19-Oct-14 8:27am    
I don't see how the event GridView1_RowDataBound() is being fired.
I think you have to add onrowdatabound="GridView1_RowDataBound"
fady_hasnaa 19-Oct-14 9:07am    
i do it but still the same problem

1 solution

Wether You want work in both modes i.e
XML
itemtemplate and in edittemplate

<pre lang="vb">If (e.Row.RowState And DataControlRowState.Alternate) &gt; 0 Then
              Dim chkBrand As CheckBoxList = DirectCast(e.Row.FindControl(&quot;chlist_item&quot;), CheckBoxList)
              chkBrand.DataSource = bal_obj.get_school_stages(scholl_id)
              chkBrand.DataTextField = &quot;stage_name&quot;
              chkBrand.DataValueField = &quot;stage_id&quot;
              chkBrand.DataBind()
              &#39; chkBrand.SelectedValue = DirectCast(e.Row.DataItem,DataRowView)(&quot;BrandID&quot;).ToString()
          End If
          If (e.Row.RowState And DataControlRowState.Edit) &gt; 0 Then
              Dim chkBrand As CheckBoxList = DirectCast(e.Row.FindControl(&quot;chlist_edit&quot;), CheckBoxList)
              chkBrand.DataSource = bal_obj.get_allstage()
              chkBrand.DataTextField = &quot;stage_name&quot;
              chkBrand.DataValueField = &quot;stage_id&quot;
              chkBrand.DataBind()
              &#39; chkBrand.SelectedValue = DirectCast(e.Row.DataItem,DataRowView)(&quot;BrandID&quot;).ToString()
          End If</pre>
 
Share this answer
 

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