locked
edit data from grideview with updatepanel RRS feed

  • Question

  • User1144299848 posted

    Hi Folks.

    I have a gridview inside a updatepanel. The gridview does not show all the data in the each row.

    I would like to let the user click on the row and display all the data in a modal pop up window, and if necessary let the user to edit it.

    My problem is how to retrieve data from the gridview, because the modal pop up window has been fired before the SelectedIndexChanged.

    HTML

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Panel ID="Panel3" runat="server">
            <table>
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="De: "></asp:Label>
                        <asp:TextBox ID="TbDe" runat="server" Width="42px"></asp:TextBox>
                    </td>
                    <td>
                        <asp:Label ID="Label2" runat="server" Text="Até: "></asp:Label>
                        <asp:TextBox ID="TbAte" runat="server" Width="43px"></asp:TextBox>
                    </td>
                    <td>
                        <asp:Button ID="Button6" runat="server" Text="   OK   "
                            OnClick="Button6_Click" />
                    </td>
                    <td>
                        <asp:Label ID="Label3" runat="server" Text="   ou   "></asp:Label>
                    </td>
                    <td>
                        <asp:Button ID="Button7" runat="server" Text="Todos os dias"
                            OnClick="Button7_Click" />
                    </td>
                    <td style="width: 30%"></td>
                    <td>
                        <asp:Button ID="Button5" runat="server" Text="Incluir" Width="153px"
                            OnClick="Button5_Click" />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </asp:Panel>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Gridview1" EventName="SelectedIndexChanged" />
            </Triggers>
            <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" Width="100%"
                        AutoGenerateColumns="False" CellPadding="4" DataKeyNames="capcod" ForeColor="#333333"
                        GridLines="None" Font-Names="Times New Roman" Font-Size="8pt"
                        OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                        OnRowDataBound="Gridview1_rowdatabound" ShowFooter="True">
                        <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <asp:ButtonField CommandName="Select" HeaderText="Cod" Text="Button" DataTextField="capcod" />
                            <asp:BoundField DataField="forfan" HeaderText="Forn" />
                            <asp:BoundField DataField="captxt" HeaderText="Desc" FooterText="Total">
                                <FooterStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="capliq" DataFormatString="{0:n2}" HeaderText="Valor">
                                <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="dia" HeaderText="Vencto" />
                            <asp:BoundField DataField="ocorrencia" HeaderText="Ocorr" />
                            <asp:BoundField DataField="cartpd" HeaderText="tpd" Visible="False" />
                            <asp:TemplateField HeaderText="Mês At Rec">
                                <ItemTemplate>
                                    <asp:CheckBox ID="Cbrec" runat="server" Checked='<%# BoxCheck(Convert.ToInt32(Eval("recebida"))) %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Mês At Transf">
                                <ItemTemplate>
                                    <asp:CheckBox ID="Cbtransf" runat="server" Checked='<%# BoxCheck(Convert.ToInt32(Eval("transferida"))) %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Prx Mês Rec">
                                <ItemTemplate>
                                    <asp:CheckBox ID="Cbprxrec" runat="server" Checked='<%# BoxCheck(Convert.ToInt32(Eval("prxrec"))) %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Prx Mês Transf">
                                <ItemTemplate>
                                    <asp:CheckBox ID="Cbprxtrans" runat="server" Checked='<%# BoxCheck(Convert.ToInt32(Eval("prxtrans"))) %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    </asp:GridView>
                    <asp:ModalPopupExtender ID="GridView1_ModalPopupExtender" runat="server" CancelControlID="Button3"  Enabled="True" PopupControlID="Panel2" TargetControlID="GridView1">
                    </asp:ModalPopupExtender>
                    <table>
                        <tr>
                            <td>
                                <asp:Button ID="Button4" runat="server" Text="Novo Mês"
                                    OnClick="Button4_Click" />
                            </td>
                            <td></td>
                            <td>&nbsp;
                            </td>
                        </tr>
                    </table>
                <asp:Panel ID="Panel2" runat="server" CssClass="modalPopup" Style="display: flexbox">
                    <table style="font: Times New Roman; font-size: 8pt; width: 100%;">
                        <tr>
                            <td style="width: 30%;"></td>
                            <td style="width: 55%;"></td>
                            <td style="width: 15%;"></td>
                        </tr>
                        <tr>
                            <td style="background-color: #CCFFFF">Codigo:
                            </td>
                            <td style="background-color: #CCFFFF">
                                <asp:Label ID="Lbcod" runat="server" Text="Label"></asp:Label>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Fornecedor:
                            </td>
                            <td>
                                <asp:Label ID="Lbfor" runat="server" Text="Label"></asp:Label>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="background-color: #CCFFFF">Descrição:
                            </td>
                            <td style="background-color: #CCFFFF;">
                                <asp:TextBox ID="Tbdesc" runat="server" Height="71px" Width="100%"
                                    Style="text-align: justify" TextMode="MultiLine"></asp:TextBox>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Valor:
                            </td>
                            <td>
                                <asp:TextBox ID="Tbval" runat="server" Text="Label" Style="width: 100%;"></asp:TextBox>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="background-color: #CCFFFF">Vencimento:
                            </td>
                            <td style="background-color: #CCFFFF">
                                <asp:TextBox ID="Tbvencto" runat="server" Style="width: 40%;"></asp:TextBox>
    
                                <asp:MaskedEditExtender ID="Tbvencto_MaskedEditExtender" runat="server"
                                    CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
                                    CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
                                    CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
                                    Mask="99/99/9999" TargetControlID="Tbvencto" MaskType="Date">
                                </asp:MaskedEditExtender>
                                <asp:CalendarExtender ID="Tbvencto_CalendarExtender" runat="server"
                                    Enabled="True" Format="dd/MM/yyyy" TargetControlID="Tbvencto">
                                </asp:CalendarExtender>
    
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Competência</td>
                            <td>
                                <asp:TextBox ID="Tbcpt" runat="server" Style="width: 40%;"></asp:TextBox>
    
                                <asp:MaskedEditExtender ID="Tbcpt_MaskedEditExtender" runat="server"
                                    CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
                                    CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
                                    CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
                                    Mask="99/99/9999" TargetControlID="Tbcpt" MaskType="Date">
                                </asp:MaskedEditExtender>
                                <asp:CalendarExtender ID="Tbcpt_CalendarExtender" runat="server" Enabled="True"
                                    Format="dd/MM/yyyy" TargetControlID="Tbcpt">
                                </asp:CalendarExtender>
    
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>Dia:
                            </td>
                            <td>
                                <asp:TextBox ID="Tbdia" runat="server" Text="Label"></asp:TextBox>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="background-color: #CCFFFF">Ocorrência:
                            </td>
                            <td style="background-color: #CCFFFF">
                                <asp:TextBox ID="Tboco" runat="server" Text="Label" Style="width: 40%;"></asp:TextBox>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Tipo de Despesa:</td>
                            <td>
                                <asp:DropDownList ID="DdlTpd" Style="width: 100%;" runat="server">
                                </asp:DropDownList>
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>Recebido: </td>
                            <td>
                                <asp:CheckBox ID="Cbrec" runat="server" />
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="background-color: #CCFFFF">Transferido:
                            </td>
                            <td style="background-color: #CCFFFF">
                                <asp:CheckBox ID="CbTrans" runat="server" />
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Próximo mês recebido:
                            </td>
                            <td>
                                <asp:CheckBox ID="Cbprxrec" runat="server" />
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td style="background-color: #CCFFFF">Próximo mês transferido:
                            </td>
                            <td style="background-color: #CCFFFF">
                                <asp:CheckBox ID="Cbprxtrans" runat="server" />
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Button ID="Button1" runat="server" Text="Transferir"
                                    OnClick="Button1_Click" />
                            </td>
                            <td style="text-align: center;">
                                <asp:Button ID="Button2" runat="server" Text="Salvar" OnClick="Button2_Click" />
                            </td>
                            <td>
                                <asp:Button ID="Button3" runat="server" Text="Excluir"
                                    OnClick="Button3_Click" />
                            </td>
                        </tr>
                    </table>
    
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>

    SelectedIndexChanged.

     protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            CheckBox cb = default(CheckBox);
            string msql = null;
            msql = "Select * from rjfin.agenda where rjfin.agenda.capcod = '" + GridView1.DataKeys[GridView1.SelectedRow.RowIndex].Value.ToString() + "'";
            cc.DBSelect(msql);
          
            Panel2.Visible = true;
            ClassTpDesp otpd = new ClassTpDesp();
            otpd.ddltpdps(ref DdlTpd);
            
            DdlTpd.SelectedIndex = DdlTpd.Items.IndexOf(DdlTpd.Items.FindByValue(cc.mdst.Tables[0].Rows[0]["captpd"].ToString()));
            Lbcod.Text = GridView1.DataKeys[GridView1.SelectedRow.RowIndex].Value.ToString();
    
            Lbfor.Text = (Server.HtmlDecode(GridView1.SelectedRow.Cells[1].Text));
            Tbdesc.Text = Server.HtmlDecode(GridView1.SelectedRow.Cells[2].Text);
            Tbval.Text = Server.HtmlDecode(GridView1.SelectedRow.Cells[3].Text);
            Tbdia.Text = Server.HtmlDecode(GridView1.SelectedRow.Cells[4].Text);
            Tboco.Text = Server.HtmlDecode(GridView1.SelectedRow.Cells[5].Text);
    
            Tbdesc.Text = Tbdesc.Text.Trim();
            Tbval.Text = Tbval.Text.Trim();
            Tbdia.Text = Tbdia.Text.Trim();
            Tboco.Text = Tboco.Text.Trim();
    
            cb = (CheckBox)GridView1.SelectedRow.Cells[6].FindControl("Cbrec");
    
            if (cb.Checked)
            {
                Cbrec.Checked = true;
            }
            else
            {
                Cbrec.Checked = false;
            }
            // Tbdia.Text.Trim();
            // Tboco.Text.Trim();
        }

    Friday, December 26, 2014 1:52 PM

Answers

All replies