2014年7月13日 星期日

[RESOLVED] [C# net4] Footer and GridView


Hi there, hope in your help.


I've my GridView empty and I tried add new record use footerTemplate.


In this code I don't have error but the footer is not visible.


Can you help me?

thank you in advance.


.cs 


protected void DecoderView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList ddlDropDownList = (DropDownList)e.Row.FindControl("Newcombo");
if (ddlDropDownList != null)
{
sql = "SELECT ...... ; ";

ddlDropDownList.DataSource = GetData(sql);
ddlDropDownList.DataTextField = "denom";
ddlDropDownList.DataValueField = "denom;
ddlDropDownList.DataBind();
ddlDropDownList.Items.Insert(0, new ListItem("------", ""));
}
}
}



protected void AddNewRecord(object sender, EventArgs e)
{
DecoderView.ShowFooter = true;
decoderViewSource();
}


private DataTable GetData(string query)
{
using (OdbcConnection con =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString))
{
using (OdbcCommand cmd =
new OdbcCommand())
{
cmd.CommandText = query;
using (OdbcDataAdapter sda = new OdbcDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
}

.aspx


                                            AutoGenerateColumns="False" PageSize="4" ShowHeader="true" OnPageIndexChanging="DecoderView_PageIndexChanging"
CssClass="mGrid" EmptyDataText="no data" DataKeyNames="ID" OnRowEditing="DecoderView_RowEditing"
OnRowCancelingEdit="DecoderView_RowCancelingEdit" OnRowCommand="DecoderView_RowCommand"
OnRowUpdating="DecoderView_RowUpdating" OnRowDeleting="DecoderView_RowDeleting"
OnRowDataBound="DecoderView_RowDataBound" ShowFooter="false"
HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White" RowStyle-BackColor="#A1DCF2"
AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000" OnDataBound="OnDataBound">










ErrorMessage="combo: Campo obbligatorio" Text="***">




ErrorMessage="combo: Campo obbligatorio" Text="***">




runat="server" />
Nessuna segnalazione attiva.




OnClick="AddNewRecord" Visible="true" />







Hi


In your gridview markup you said ShowFooter="false" set this to [true]. Footer will come up


沒有留言:

張貼留言