How to bind a particular database field in Grid view as 2 columns.
As usual all data added row wise only.
1
2
3
4
5
6
7
8
9
10
I need that in 2 column like
1 2 1 6
3 4 2 7
5 6 or 3 8
7 8 4 9
9 10 5 10
so far i have used like below. Please suggest to change this code based on above requirement.
OnRowDataBound="GridCatg_RowDataBound" PageIndex="3" PageSize="10">
AutoPostBack="False" Height="40px">
private void BindGrid()
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["constr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from AS_CATG_MASTER";
cmd.Connection = conn;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
GridCatg.DataSource = ds;
GridCatg.DataBind();
conn.Close();
}
}
}
protected void GridCatg_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Binding checkbox list to Gridview
if (e.Row.RowIndex != -1 && e.Row.DataItem != null)
{
object objTemp = GridCatg.DataKeys[e.Row.RowIndex].Value as object;
if (objTemp != null)
{
Catgname = objTemp.ToString();
//Do your operations
}
//Itendifying checkboxlist in gridview template column
CheckBox chkall = (CheckBox)e.Row.Cells[0].FindControl("cbAll");
chkall.Text = Catgname;
CheckBoxList chklist = (CheckBoxList)e.Row.Cells[0].FindControl("cb_CATG_FORM");
DataSet bpds = ExecuteDataset(sDsn, "select * from AS_CATG_FORM WHERE HCF_CATG_CD='" + Catgname + "'");
if (bpds.Tables.Count > 0)
{
if (bpds.Tables[0].Rows.Count > 0)
{
//Assigning DataSource to checkboxlist
chklist.DataSource = bpds.Tables[0];
chklist.DataTextField = "HCF_FORM_CD";
chklist.DataValueField = "HCF_FORM_CD";
chklist.DataBind();
//chklist.Items.Insert(0, new ListItem(Catgname));
}
}
chkall.Attributes.Add("onclick", "CallChk('" + chklist.ClientID.ToString() + "','" + chklist.Items.Count + "','" + chkall.ClientID.ToString() + "')");
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
rajendra singhPosted Nov 17, 2017, 4:45 AM
SeethaParthaPosted Nov 24, 2017, 12:08 AM