//THE HTML TAGS OF A DATAGRID
<div>
<asp:GridView ID="GridView1" CssClass="xGridViewPro" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="300px" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating" AllowPaging="True" ShowFooter="True" OnRowCommand="GridView1_RowCommand" OnPageIndexChanging="GridView1_PageIndexChanging" >
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtnameEdit" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
<asp:Label ID="lblvalue" runat="server" Text='<%# Bind("value") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValueEdit" runat="server" Text='<%# Bind("value") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootValue" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comment">
<ItemTemplate>
<asp:Label ID="lblcomment" runat="server" Text='<%# Bind("comment") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtcommentEdit" runat="server" Text='<%# Bind("comment") %>'> </asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootComment" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="id">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%# Bind("id") %>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="BtnADD" runat="server" Text="Add" CommandName="addrow" />
</FooterTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="rowdelete" Text="Delete" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>
*******************************************************************************
IN CODE BEHIND-->CODE SAMPLE
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label5.Visible = false;
GridView1.EditIndex = e.NewEditIndex;
loadGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
int index = GridView1.EditIndex;
int a = e.RowIndex;
GridViewRow row = GridView1.Rows[index];
Label Codelblid = (Label)GridView1.Rows[e.RowIndex].FindControl("lblid");
TextBox CodetxtnameEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtnameEdit");
TextBox CodetxtValueEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValueEdit");
TextBox CodetxtcommentEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcommentEdit");
string id = Codelblid.Text;
string name = CodetxtnameEdit.Text;
string value = CodetxtValueEdit.Text;
string comment = CodetxtcommentEdit.Text;
Label5.Visible = true;
if (UpdateTheDetails(id, name, value, comment))
{
try
{
GlobalValues objGlob = GlobalValues.SET();
}
catch
{
}
GridView1.EditIndex = -1;
loadGrid();
Label5.Text = "Global value Updated Successfully";
}
else
{
Label5.Text = "Sorry..Error ocuured..Global values not updated..";
Label5.BackColor = Color.Red;
}
}
catch { }
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
Label5.Visible = false;
GridView1.EditIndex = -1;
loadGrid();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
Label5.Visible = true;
if (e.CommandName == "addrow")
{
// int index = Convert.ToInt32(e.CommandArgument);
TextBox CodetxtnameEdit = (TextBox)GridView1.FooterRow.FindControl("txtfootName");
TextBox CodetxtValueEdit = (TextBox)GridView1.FooterRow.FindControl("txtfootValue");
TextBox CodetxtcommentEdit = (TextBox)GridView1.FooterRow.FindControl("txtfootComment");
string name = CodetxtnameEdit.Text;
string value = CodetxtValueEdit.Text;
string comment = CodetxtcommentEdit.Text;
string validSTR=Validate(name, value, comment);
if (validSTR == "true")
{
if (INSERTTheDetails(name, value, comment))
{
loadGrid();
}
}
else
{
Label5.BackColor = Color.Red;
}
}
else if (e.CommandName == "rowdelete")
{
int index = Convert.ToInt32(e.CommandArgument);
Label Codelblid = (Label)GridView1.Rows[index].FindControl("lblid");
string id = Codelblid.Text;
if (DELETETheDetails(id))
{
loadGrid();
}
}
}
catch { }
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Label5.Visible = false;
GridView1.PageIndex = e.NewPageIndex;
loadGrid();
}
Tuesday, December 15, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment